We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10378
    • 375 Posts
    Hi,

    the following post will probably confuse you as I don't know how to explain better:
    How can I setup the transport package for an add-on to support both Revo 2.2.x and 2.3 CMPs?

    I just installed the current transport package of my add-on (built for 2.2.x) in Revo 2.3 and it seems to work as expected (except for some strange errors - eg. some processor files aren't found and so on...) . The problem is, my installer uses the deprecated (for 2.3) modAction method to create the link to the controller.

    So I followed the instructions in this tutorial to use the new method but can't get it to work:

    http://rtfm.modx.com/revolution/2.x/developing-in-modx/advanced-development/custom-manager-pages/custom-manager-pages-in-2.3

    I have attached screenshots which shows the location of the index controller class + the home controller of my CMP + the configuration dialogue for the menu entry below. This is the setup was built using the tutorials for creating CMPs under Revo 2.x.

    The file tree to show the location of the controller file (the home controller for this CMP is home.class.php which is called by the index.class.php):



    The configuration dialogue for the menu entry:



    This produces the following URL (domain part removed):
    ../manager/index.php?a=home&namespace=goodnews


    Clicking the menu entry leads to a white page.

    Any hints on this problem?

    Edit: do I really have to add another subdirectory (in tutorial they are using "default") to hold the controller for the CMP? This would break the package for 2.2.x - or what am I missing here?

    Thanks,
    Martin [ed. note: gadgetto last edited this post 12 years, 11 months ago.]
      Freelancer @bitego http://www.bitego.com
      ---
      GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
      More infos here: http://www.bitego.com/extras/goodnews/
      • 3749
      • 24,544 Posts
      It looks like you do need the default/ directory.

      I think if you change your index.php file in the goodnews directory to 'include' the home controller in the default directory, it should work in both 2.2 and 2.3. I could be wrong.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 10378
        • 375 Posts
        Quote from: BobRay at Nov 03, 2013, 04:05 PM
        It looks like you do need the default/ directory.

        I think if you change your index.php file in the goodnews directory to 'include' the home controller in the default directory, it should work in both 2.2 and 2.3. I could be wrong.

        Thank you Bob, I'll try this.
          Freelancer @bitego http://www.bitego.com
          ---
          GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
          More infos here: http://www.bitego.com/extras/goodnews/
          • 4172
          • 5,888 Posts
          @gadgetto

          How did you set up your transport.menus.php to work in both, 2.2.x and in 2.3.0 ?

          I've tried

          $action = $modx->newObject('modAction');
          $action->fromArray(array(
              'namespace' => 'migx',
              'controller' => 'index',
              'haslayout' => 1,
              'lang_topics' => 'example:default',
              'assets' => '',
              'help_url' => '',
              'id' => 1,
              ), '', true, true);
          
          
          $menus[1] = $modx->newObject('modMenu');
          $menus[1]->fromArray(array(
              'text' => 'migx',
              'parent' => 'components',
              'description' => '',
              'icon' => '',
              'menuindex' => 0,
              'params' => '&configs=packagemanager||migxconfigs||setup',
              'handler' => '',
              'permissions' => '',
              'namespace' => 'migx',
              'action' => 'index',
              ), '', true, true);
          
          $menus[1]->addOne($action);
          
          return $menus;
          


          But the result in 2.3 was

          http://www.revo230.webcmsolutions.de/manager/index.php?a=0&namespace=migx&configs=packagemanager||migxconfigs||setup


          but should be:

          http://www.revo230.webcmsolutions.de/manager/index.php?a=index&namespace=migx&configs=packagemanager||migxconfigs||setup


          when I add 'index' to the action manually, it does work, of course.


            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 10378
            • 375 Posts
            Revo 2.3 should be able to handle both (new + old) methods.
            I didn't check back this for a while (probably I should reinstall the package on a fresh 2.3) but here is my transport.menus.php:

            // Create action
            $action = $modx->newObject('modAction');
            $action->fromArray(array(
                'id'          => 1,
                'namespace'   => 'goodnews',
                'parent'      => 0,
                'controller'  => 'index',
                'haslayout'   => true,
                'lang_topics' => 'goodnews:default',
                'assets'      => '',
            ), '', true, true);
            
            // Load action into menu
            $menu = $modx->newObject('modMenu');
            $menu->fromArray(array(
                'text'        => 'goodnews',
                'parent'      => 'components',
                'description' => 'goodnews.desc',
                'icon'        => '',
                'menuindex'   => 0,
                'params'      => '',
                'handler'     => '',
            ), '', true, true);
            
            $menu->addOne($action);
            return $menu;
            


            leads to this menu link:

            http://modxpre.bitego.com/revo2.3/manager/?a=3


            I need to say that this didn't work until a nightly build about 1 month ago. Which nightly do you use? [ed. note: gadgetto last edited this post 12 years, 6 months ago.]
              Freelancer @bitego http://www.bitego.com
              ---
              GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
              More infos here: http://www.bitego.com/extras/goodnews/
              • 33976 ☆ A M B ☆
              • 571 Posts
              For what it worth... modAction entries are deprecated (but still supported for backward compatibility).

              Since i started putting my manager controllers in a "default" directory, i ship them with 2 classes within the controller :

              File : controllers/default/welcome.class.php

              // Revo 2.3 "style"
              class MyExtraWelcomeManagerController extends modExtraManagerController
              {
              // code
              }
              
              // Revo 2.2
              class MyExtraDefaultWelcomeManagercontroller extends MyExtraMAnagerController 
              {
              
              }
              


              Since modAction are deprecated, i package 2 menus, and use some validators to find the Revo version and install the appropriate menu :

              File build.transport.php

              // some code you are used to
              
              // Load menu
              $modx->log(modX::LOG_LEVEL_INFO, 'Packaging in menu 2.2...');
              $menu = include $sources['data'] . 'transport.menu-2.2.php';
              if (empty($menu)) {
                  $modx->log(modX::LOG_LEVEL_ERROR, 'Could not package in menu.');
              }
              $vehicle = $builder->createVehicle($menu, array (
                  xPDOTransport::PRESERVE_KEYS => true,
                  xPDOTransport::UPDATE_OBJECT => true,
                  xPDOTransport::UNIQUE_KEY => 'text',
                  xPDOTransport::RELATED_OBJECTS => true,
                  xPDOTransport::RELATED_OBJECT_ATTRIBUTES => array (
                      'Action' => array (
                          xPDOTransport::PRESERVE_KEYS => false,
                          xPDOTransport::UPDATE_OBJECT => true,
                          xPDOTransport::UNIQUE_KEY => array ('namespace', 'controller'),
                      ),
                  ),
              ));
              $modx->log(modX::LOG_LEVEL_INFO, 'Adding in PHP resolvers...');
              $vehicle->validate('php', array(
                  'source' => $sources['validators'] . 'modx-2.2.php',
              ));
              $builder->putVehicle($vehicle);
              unset($vehicle, $menu);
              
              
              $modx->log(modX::LOG_LEVEL_INFO, 'Packaging in menu for 2.3+...');
              $menu = include $sources['data'] . 'transport.menu-2.3.php';
              if (empty($menu)) {
                  $modx->log(modX::LOG_LEVEL_ERROR, 'Could not package in menu.');
              }
              $vehicle = $builder->createVehicle($menu, array (
                  xPDOTransport::PRESERVE_KEYS => true,
                  xPDOTransport::UPDATE_OBJECT => true,
                  xPDOTransport::UNIQUE_KEY => 'text',
              ));
              $vehicle->validate('php', array(
                  'source' => $sources['validators'] . 'modx-2.3.php',
              ));
              $builder->putVehicle($vehicle);
              unset($vehicle, $menu);
              


              transport.menu-2.3.php being most likely the same as you guys are used to, without the action (so basically just a transport for the modMenu entry), action attribute being the name of your action (welcome in this example).

              And a sample validator :

              File validators/modx-2.3php

              $success = false;
              if ($object->xpdo) {
                  /** @var modX $modx */
                  $modx =& $object->xpdo;
              
                  $modx->getVersionData();
                  if (version_compare($modx->version['full_version'], '2.3', '>=')) {
                      $success = true;
                  } else {
                      $modx->log(modX::LOG_LEVEL_WARN, 'Skipping menu for MODX Revolution 2.3');
                  }
              }
              
              return $success;
              


              Hope it makes sense and might be helpful
                • 4172
                • 5,888 Posts
                thanks to you both!

                romain, that sounds exactly like that, what I was looking for, a validator.
                Will try that tomorrow.

                Thanks!
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 4172
                  • 5,888 Posts
                  This seems to work great!

                  Building the package within 2.2.14, I had to change the php-type of the action-field from int to string, otherwise I got allways a action of 0, which does make sense with a phptype of int

                  transport.menu-2.3.x.php:
                  $menus[1] = $modx->newObject('modMenu');
                  $menus[1]->_fieldMeta['action']['phptype'] = 'string';
                  $menus[1]->fromArray(array(
                      'text' => 'migx',
                      'parent' => 'components',
                      'description' => '',
                      'icon' => '',
                      'menuindex' => 0,
                      'params' => '&configs=packagemanager||migxconfigs||setup',
                      'handler' => '',
                      'permissions' => '',
                      'namespace' => 'migx',
                      'action' => 'index',
                      ), '', true, true);
                  
                  return $menus;
                  


                  Couldn't find any examples for validators on rtfm.

                  I think, I should add this whole information here

                  http://rtfm.modx.com/revolution/2.x/developing-in-modx/advanced-development/package-management/creating-a-3rd-party-component-build-script#Creatinga3rdPartyComponentBuildScript-ValidatorsandResolvers

                  if not anyone else with better english wants to do it.

                  Anyone?

                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    Go ahead, Bruno. If there's any problem with the English that makes it too confusing, I'm sure there will be somebody to fix it wink
                      Studying MODX in the desert - http://sottwell.com
                      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                      Join the Slack Community - http://modx.org
                      • 33976 ☆ A M B ☆
                      • 571 Posts
                      Bruno, if you would have packaged your component with Revo 2.3 (i assume you did it on a 2.2 core), i doubt you would have to change the field type since the schema/maps are updated.