We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28215
    • 4,149 Posts
    The MODx Team would like to introduce a new tutorial:

    Creating a 3rd Party Component Build Script

    This tutorial teaches how to create a 3PC (3rd Party Component) build script for your components. It goes through all the basics, including but not limited to:


    • Vehicle Attributes
    • Related Objects
    • Resolvers
    • Lexicon Packaging
    • Package Attributes
    • Pre-install (Setup) Options

    This tutorial is applicable to Revolution 2.0-SVN r4953 or later, and/or Revolution 2.0-beta-1.

    Thanks,
    MODx Team
      shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
      • 17499 ☆ A M B ☆
      • 872 Posts
      Wow, that’s pretty neat!
        • 8643
        • 271 Posts
        Where is the resource files for quip?
        Can’t find it in SVN.
          • 16183
          • 1,390 Posts
          Quote from: elastic at May 11, 2009, 07:29 AM

          Where is the resource files for quip?
          Can’t find it in SVN.

          http://modxcms.com/extras.html?view=package/view&package=538
            • 8643
            • 271 Posts
            Quote from: kongondo at May 11, 2009, 08:06 AM

            http://modxcms.com/extras.html?view=package/view&package=538
            No, it’s transport package.
              • 16183
              • 1,390 Posts
              Oops, sorry, should have read the post carefully wink
                • 28215
                • 4,149 Posts
                It’s not yet available in public SVN until we finish with testing on it. Soon. smiley
                  shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                  • 29597 ☆ A M B ☆
                  • 350 Posts
                  I am a bit stuck,

                  I created a Build script and it looks like it is working.
                  At the moment it creates a category.

                  But if I try to creater a snippet I get no errors, but the script is not running.

                  Code:

                  build.transport.php

                  <?php
                  /**
                   * MODULAR build script
                   *
                   * @package modular
                   * @subpackage build
                   */
                  $mtime = microtime();
                  $mtime = explode(" ", $mtime);
                  $mtime = $mtime[1] + $mtime[0];
                  $tstart = $mtime;
                  set_time_limit(0); /* makes sure our script doesnt timeout */
                  
                  $root = dirname(dirname(__FILE__)).'/';
                  $sources= array (
                      'root' => $root,
                      'build' => $root .'_build/',
                      'resolvers' => $root . '_build/resolvers/',
                      'data' => $root . '_build/data/',
                      'source_core' => $root.'core/components/modular',
                      'source_assets' => $root.'assets/templates/main',
                      'docs' => $root.'core/components/modular/docs/',
                  );
                  unset($root); /* save memory */
                  
                  require_once dirname(__FILE__) . '/build.config.php';
                  
                  require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
                   
                  $modx= new modX();
                  $modx->initialize('mgr');
                  $modx->setLogLevel(modX::LOG_LEVEL_INFO);
                  $modx->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML');
                  
                  $modx->loadClass('transport.modPackageBuilder','',false, true);
                  $builder = new modPackageBuilder($modx);
                  $builder->createPackage('modular','0.1','alpha1');
                  $builder->registerNamespace('modular',false,true,'{core_path}components/modular/');
                  
                  
                  
                  /* load action/menu */
                  $action = include $sources['data'].'transport.action.php';
                  
                  $vehicle= $builder->createVehicle($action,array (
                      XPDO_TRANSPORT_PRESERVE_KEYS => false,
                      XPDO_TRANSPORT_UPDATE_OBJECT => true,
                      XPDO_TRANSPORT_UNIQUE_KEY => array ('namespace','controller'),
                      XPDO_TRANSPORT_RELATED_OBJECTS => true,
                      XPDO_TRANSPORT_RELATED_OBJECT_ATTRIBUTES => array (
                          'Menus' => array (
                              XPDO_TRANSPORT_PRESERVE_KEYS => false,
                              XPDO_TRANSPORT_UPDATE_OBJECT => true,
                              XPDO_TRANSPORT_UNIQUE_KEY => array ('action', 'text'),
                          ),
                      ),
                  ));
                  $builder->putVehicle($vehicle);
                  unset($vehicle,$action);
                  
                  /* load system settings */
                  $settings = array();
                  include_once $sources['data'].'transport.settings.php';
                  
                  $attributes= array(
                      XPDO_TRANSPORT_UNIQUE_KEY => 'key',
                      XPDO_TRANSPORT_PRESERVE_KEYS => true,
                      XPDO_TRANSPORT_UPDATE_OBJECT => false,
                  );
                  foreach ($settings as $setting) {
                      $vehicle = $builder->createVehicle($setting,$attributes);
                      $builder->putVehicle($vehicle);
                  }
                  unset($settings,$setting,$attributes);
                  
                  
                  /* create category */
                  $category= $modx->newObject('modCategory');
                  $category->set('id',1);
                  $category->set('category','MODULAR');
                  
                  
                  /* create the snippet */
                  $snippet= $modx->newObject('modSnippet');
                  $snippet->set('id',0);
                  $snippet->set('name', 'include');
                  $snippet->set('description', 'Includes template code dynamically.');
                  $snippet->set('snippet',file_get_contents($sources['source_core'].'/snippet.include.php');
                  
                  /* add chunks */
                  $chunks = include $sources['data'].'transport.chunks.php';
                  if (is_array($chunks)) {
                      $category->addMany($chunks);
                  } else { $modx->log(MODX_LOG_LEVEL_FATAL,'Adding chunks failed.'); }
                  
                  /* create category vehicle */
                  $attr = array(
                      XPDO_TRANSPORT_UNIQUE_KEY => 'category',
                      XPDO_TRANSPORT_PRESERVE_KEYS => false,
                      XPDO_TRANSPORT_UPDATE_OBJECT => true,
                      XPDO_TRANSPORT_RELATED_OBJECTS => true,
                      XPDO_TRANSPORT_RELATED_OBJECT_ATTRIBUTES => array (
                          'modSnippet' => array(
                              XPDO_TRANSPORT_PRESERVE_KEYS => false,
                              XPDO_TRANSPORT_UPDATE_OBJECT => true,
                              XPDO_TRANSPORT_UNIQUE_KEY => 'name',
                          ),
                          'modChunk' => array (
                              XPDO_TRANSPORT_PRESERVE_KEYS => false,
                              XPDO_TRANSPORT_UPDATE_OBJECT => true,
                              XPDO_TRANSPORT_UNIQUE_KEY => 'name',
                          ),
                      )
                  );
                  $vehicle = $builder->createVehicle($category,$attr);
                  $vehicle->resolve('file',array(
                      'source' => $sources['source_core'],
                      'target' => "return MODX_CORE_PATH . 'components/';",
                  ));
                  $vehicle->resolve('file',array(
                      'source' => $sources['source_assets'],
                      'target' => "return MODX_ASSETS_PATH . 'components/';",
                  ));
                  $vehicle->resolve('php',array(
                      'source' => $sources['resolvers'] . 'setupoptions.resolver.php',
                  ));
                  $builder->putVehicle($vehicle);
                  
                  /* now pack in the license file, readme and setup options */
                  $builder->setPackageAttributes(array(
                      'license' => file_get_contents($sources['docs'] . 'license.txt'),
                      'readme' => file_get_contents($sources['docs'] . 'readme.txt'),
                      'setup-options' => array(
                          'source' => $sources['build'].'setup.options.php',
                      ),
                  ));
                  
                  $builder->pack();
                  
                  $mtime= microtime();
                  $mtime= explode(" ", $mtime);
                  $mtime= $mtime[1] + $mtime[0];
                  $tend= $mtime;
                  $totalTime= ($tend - $tstart);
                  $totalTime= sprintf("%2.4f s", $totalTime);
                  
                  $modx->log(MODX_LOG_LEVEL_INFO,"\n<br />Package Built.<br />\nExecution time: {$totalTime}\n");
                  
                  exit ();


                  The ERROR I get:
                  Parse error: syntax error, unexpected ';' in /home/mennopp/domains/nieuwe-website-ontwerpen.nl/public_html/modular/modular/Source Files/trunk/_build/build.transport.php on line 88
                  


                  Line 88 is the final line of the /* create the snippet */ block, but what is wrong with it?
                  If I remove the /* create the snippet */ block the script runs fine...

                  Also, after I remove the /* create the snippet */ block the category is created fine, so the script runs and works, but the add chunk function is not working (gives no errors)

                  the transport.chunks.php code:
                  <?php
                  /**
                  * @package modular
                  * @subpackage build
                  */
                  $chunks = array();
                  
                  $chunks[1]= $modx->newObject('modChunk');
                  $chunks[1]->fromArray(array(
                      'id' => 1,
                      'name' => 'GalAlbumRowTpl',
                      'description' => 'Slider album row template.',
                      'snippet' => file_get_contents($sources['data'].'chunks/chunk.GalAlbumRowTpl.txt'),
                  ),'',true,true);
                  
                  return $chunks;
                  


                  The chunk.GalAlbumRowTpl.txt code:
                  <div class="albumPreview">
                      <h3><a href="[[~[[*id]]? &[[+albumRequestVar]]=`[[+id]]`]]">[[+name]]</a></h3>
                      <div class="thumb">
                          <a href="[[~[[*id]]? &[[+albumRequestVar]]=`[[+id]]`]]"><img src="[[+image]]" alt="[[+name]]" /></a>
                      </div>
                      <div class="desc">
                          <p>[[+description]]</p>
                      </div>
                  </div>
                  


                  I checked all the paths, the look fine. But my site is in a subfolder, could that be the problem?

                  UPDATE:

                  If I use the code from here: http://modxcms.com/assets/tutorials/3pc/build.transport.phps (the create the snippet block) it gives the same error
                    MODX Ambassador (NL) | Responsive web design specialist, developer & speaker
                    DESIGNfromWITHIN, MPThemes and Any Screen Size
                    Follow me on Twitter | Read my blog | My code on GitHub
                    • 24068
                    • 4 Posts
                    You forgott to close one (

                    Just add a ) before ;

                    $snippet->set('snippet',file_get_contents($sources['source_core'].'/snippet.include.php'));


                      • 29597 ☆ A M B ☆
                      • 350 Posts
                      OK everything seems to be working Packing and installing chunks, snippets, TV’s, template files and other packages!
                      My project is coming a long nicely.

                      I do still have one small issue:

                      I use MIGX to create slides for a jQuery slider.
                      To get it to work I need a TV called multiItemsGrid and under Input options need to add:

                      Form Tabs:
                      [
                      {"caption":"Info", "fields": [
                          {"field":"title","caption":"Title","description":"Title for the image."},
                          {"field":"description","caption":"Description","inputTV":"richtext"},
                      	{"field":"slide_option","caption":"Slide type","inputTV":"slide_option"}
                      ]},
                      {"caption":"Image", "fields":[
                          {"field":"image","caption":"Image","inputTV":"image"}
                      ]}
                      ] 


                      Grid Columns:
                      [
                      {"header": "Title", "width": "160", "sortable": "true", "dataIndex": "title"},
                      {"header": "Image", "width": "50", "sortable": "false", "dataIndex": "image","renderer": "this.renderImage"}
                      ]


                      Now my question is how do I add this code with a Build Script?

                      I use this and the MIGX TV is added and the input settings is migx, but the form and grid settings are not added.

                      $tvs[2]= $modx->newObject('modTemplateVar');
                      $tvs[2]->fromArray(array(
                          'id' => 2,
                          'name' => 'multiItemsGrid',
                          'caption' => 'Slider items',
                          'description' => 'The items in the slider',
                          'category' => 'MODULAR',
                          'type' => 'migx',
                          'display' => 'default',
                          'locked' => 0,
                          'rank' => 0,
                          'default_text' => '',
                          'display_params' => '',
                          'formtabs2' => '
                      [
                      {"caption":"Info", "fields": [
                          {"field":"title","caption":"Title","description":"Title for the image."},
                          {"field":"description","caption":"Description","inputTV":"richtext"},
                          {"field":"slide_option","caption":"Slide type","inputTV":"slide_option"}
                      ]},
                      {"caption":"Image", "fields":[
                          {"field":"image","caption":"Image","inputTV":"image"}
                      ]}
                      ]
                      	',
                          'columns2' => '
                      [
                      {"header": "Title", "width": "160", "sortable": "true", "dataIndex": "title"},
                      {"header": "Image", "width": "50", "sortable": "false", "dataIndex": "image","renderer": "this.renderImage"}
                      ]
                      	',
                      ),'',true,true);


                      Any help?
                      B.t.w. This Build Script thing is very cool! Thinking about many projects with it!
                        MODX Ambassador (NL) | Responsive web design specialist, developer & speaker
                        DESIGNfromWITHIN, MPThemes and Any Screen Size
                        Follow me on Twitter | Read my blog | My code on GitHub