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

    I've created a new extra for modx, and now i'm in the process of packaging the component.

    The code below adds the menus into my package (transporter.menu.php)

    <?php
    $menus = array();
    
    $action= $modx->newObject('modAction');
    $action->fromArray(array(
        'id' => 1,
        'namespace' => 'icposts',
        'parent' => 0,
        'controller' => 'post_controllers/index',
        'haslayout' => true,
        'lang_topics' => 'icposts:default',
        'assets' => '',
    ),'',true,true);
     
    $menu= $modx->newObject('modMenu');
    $menu->fromArray(array(
        'text' => 'icposts',
        'parent' => 'components',
        'description' => 'icposts.desc',
        'icon' => '',
        'menuindex' => 0,
        'params' => '',
        'handler' => '',
    ),'',true,true);
    
    $action2= $modx->newObject('modAction');
    $action2->fromArray(array(
        'id' => 2,
        'namespace' => 'icposts',
        'parent' => 1,
        'controller' => 'post_controllers/add',
        'haslayout' => true,
        'lang_topics' => icposts:default',
        'assets' => '',
    ),'',true,true);
     
    $menu2= $modx->newObject('modMenu');
    $menu2->fromArray(array(
        'text' => 'icposts.post_create',
        'parent' => 'icposts',
        'description' => 'icposts.post_create_desc',
        'icon' => '',
        'menuindex' => 1,
        'params' => '&action=add',
        'handler' => '',
    ),'',true,true);
    
    $menu->addOne($action);
    $menu2->addOne($action2);
    
    
    $menus[]=$menu;
    $menus[]=$menu2;
    
    
    unset($menu);
    unset($menu2);
     
    return $menus;


    and the build.transporter.php

    /* load menu */
    $modx->log(modX::LOG_LEVEL_INFO,'Packaging in menu...');
    $menus = include $sources['data'].'transport.menu.php';
    if (empty($menus)) $modx->log(modX::LOG_LEVEL_ERROR,'Could not package in menu.');
    
    foreach($menus as $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'),
    	        ),
    	    ),
    	));
    	
    	$builder->putVehicle($vehicle);
    	
    	//unset($vehicle,$menu);
    	
    }
    
    $modx->log(modX::LOG_LEVEL_INFO,'Adding in PHP resolvers...');
    $vehicle->resolve('php',array(
        'source' => $sources['resolvers'] . 'resolve.tables.php',
    ));
    
    $builder->putVehicle($vehicle);


    when I install the package, the menu gets added, but the action is not for the second action '$action2', but it's inside the database, and the forms work fine, but still I can't see the action under the namespace in the MODx manager.

    and also, is this a good way to do the sub-menus and multiple menus for an extra.

    Thanks in advance

    devteam@moon
      • 3749
      • 24,544 Posts
      I think you need this in your resolver:

      $menu->save();
      $menu2->save();
        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
        • 36420
        • 9 Posts
        Thanks BobRay for the reply

        These save statements gave me many errors after adding them into the transporter.menu.php:

        [2011-10-05 18:10:14] (ERROR @ /innercircleposts/_build/build.transport.php) Error 23000 executing statement:
        INSERT INTO `modx_actions` (`id`, `namespace`, `parent`, `controller`, `haslayout`, `lang_topics`, `assets`, `help_url`) VALUES (1, 'innercircleposts', 0, 'post_controllers/index', 1, 'innercircleposts:default', '', '')
        Array
        (
            [0] => 23000
            [1] => 1062
            [2] => Duplicate entry '1' for key 'PRIMARY'
        )
        
        [2011-10-05 18:10:14] (ERROR @ /innercircleposts/_build/build.transport.php) Error 23000 executing statement:
        INSERT INTO `modx_menus` (`text`, `parent`, `action`, `description`, `icon`, `menuindex`, `params`, `handler`, `permissions`) VALUES ('innercircleposts', 'components', 1, 'innercircleposts.desc', '', 0, '', '', '')
        Array
        (
            [0] => 23000
            [1] => 1062
            [2] => Duplicate entry 'innercircleposts' for key 'PRIMARY'
        )
        
        [2011-10-05 18:10:14] (ERROR @ /innercircleposts/_build/build.transport.php) Error 23000 executing statement:
        INSERT INTO `modx_actions` (`id`, `namespace`, `parent`, `controller`, `haslayout`, `lang_topics`, `assets`, `help_url`) VALUES (1, 'innercircleposts', 0, 'post_controllers/index', 1, 'innercircleposts:default', '', '')
        Array
        (
            [0] => 23000
            [1] => 1062
            [2] => Duplicate entry '1' for key 'PRIMARY'
        )
        
        [2011-10-05 18:10:14] (ERROR @ /innercircleposts/_build/build.transport.php) Error 23000 executing statement:
        INSERT INTO `modx_actions` (`id`, `namespace`, `parent`, `controller`, `haslayout`, `lang_topics`, `assets`, `help_url`) VALUES (2, 'innercircleposts', 1, 'post_controllers/add', 1, 'innercircleposts:default', '', '')
        Array
        (
            [0] => 23000
            [1] => 1062
            [2] => Duplicate entry '2' for key 'PRIMARY'
        )
        
        [2011-10-05 18:10:14] (ERROR @ /innercircleposts/_build/build.transport.php) Error 23000 executing statement:
        INSERT INTO `modx_menus` (`text`, `parent`, `action`, `description`, `icon`, `menuindex`, `params`, `handler`, `permissions`) VALUES ('innercircleposts.post_create', 'innercircleposts', 2, 'innercircleposts.post_create_desc', '', 1, '&action=add', '', '')
        Array
        (
            [0] => 23000
            [1] => 1062
            [2] => Duplicate entry 'innercircleposts.post_create' for key 'PRIMARY'
        )
        
        [2011-10-05 18:10:14] (ERROR @ /innercircleposts/_build/build.transport.php) Error 23000 executing statement:
        INSERT INTO `modx_actions` (`id`, `namespace`, `parent`, `controller`, `haslayout`, `lang_topics`, `assets`, `help_url`) VALUES (2, 'innercircleposts', 1, 'post_controllers/add', 1, 'innercircleposts:default', '', '')
        Array
        (
            [0] => 23000
            [1] => 1062
            [2] => Duplicate entry '2' for key 'PRIMARY'
        )


        You said that I have to add them into the resolver, but I have only one resolver, which is the one to create the tables. Is that possible to add the two statements there?

        Thx

        devteam@moon


          • 43501
          • 1 Posts
          Thanks crazysnake

          This script statement is very good for work