Chunks

Chunk can be created or updated with a migration.

If you have not done so, generate a migration class. See the Local or Package development docs for more info.

Example:

<?php
    
/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    /** @var \LCI\Blend\Blendable\Chunk $myChunk */
    $myChunk = $this->blender->getBlendableLoader()->getBlendableChunk('myChunk');
    
    // replace my/package with your Composer Package name as listed on your composer.json file
    // Then the full relative file path of your file
    $myChunk
        ->setSeedsDir($this->getSeedsDir())// This is needed to set the down() data
        ->setFieldDescription('This is my local test chunk, note this is limited to 255 or something')
        ->setFieldCategory('My Site=>Chunks')
        //  file path                                          Media Source name, assuming you do not change the default MODX file system media source:
        ->setAsStatic('core/components/local/elements/chunk/myChunk.tpl', 'filesystem');
        // OR see the Local and Package Development documents for more info
        //->setAsStatic('my/project/src/elements/chunks/myChunk.tpl','orchestrator');
    
    // The blend() method will create a back/down data before saving to allow for easy revert with the revertBlend method
    if ($myChunk->blend(true)) {
        $this->blender->out($myChunk->getFieldName().' was saved correctly');
    
    } else {
        //error
        $this->blender->outError($myChunk->getFieldName().' did not save correctly ');
        $this->blender->outError(print_r($myChunk->getErrorMessages(), true), \LCI\Blend\Blender::VERBOSITY_DEBUG);
    }
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    /** @var \LCI\Blend\Blendable\Chunk $myChunk */
    $myChunk = $this->blender->getBlendableLoader()->getBlendableChunk('myChunk');
    $myChunk->setSeedsDir($this->getSeedsDir());// This is needed to retrieve the down data
    
    if ( $myChunk->revertBlend() ) {
        $this->blender->out($myChunk->getFieldName().' chunk has been reverted to '.$this->getSeedsDir());
    
    } else {
        $this->blender->outError($myChunk->getFieldName().' chunk was not reverted');
    }
}

Chunk seeds

Create chunk seeds for work that you have completed within the MODX Manager and you wish to export one more chunks to another instance.

Simple example

Run:

cd /www/core/
php vendor/bin/orchestrator blend:seed --object chunk

You will then be prompted for enter in a comma separated list of chunk names or IDs to include.

A migration file with a timestamp will be created and then a new directory for all of the seed data:

core/components/blend/database/migrations/m2019_08_16_180000_Chunk.php
core/components/blend/database/seeds/m2019_08_16_180000_Chunk/elements

Select Chunks

Pass chunk IDs as an option for the command as a comma separated list of IDs. Example seed chunks with the IDs 2 and 3.

cd /www/core/
php vendor/bin/orchestrator blend:seed  --object chunk --id 2,3

Give your migration a custom name, maybe for a version or bug number:

cd /www/core/
php vendor/bin/orchestrator blend:seed  --object chunk --name Issue1234

Customize Chunks

If you want to customize the content on export you can write a plugin using the following events:

  • OnBlendBeforeSave
  • OnBlendAfterSave
  • OnBlendSeed
  • OnBlendLoadRelatedData