Including a Block in a Package

If you haven't, check out the documentation on packaging a theme. Here you'll learn the ins and outs on the Concrete CMS package format, a package's Controller file and get up to speed quickly.

Once you have your package's Controller file created, it's a simple matter to add support for your custom block to the package.

Create a blocks directory within your package's directory. If we're making a package for our audio player block, Let's create a package for it

mkdir packages/audio_player
mkdir packages/audio_player/blocks/

Create a controller file for your package as per the theming instructions listed above. Move your audio player block from application/blocks/audio_player into the package.

mv application/blocks/audio_player packages/audio_player/blocks/audio_player

Change the name space fo your audo_player block to Concrete\Package\AudioPlayer\Block\AudioPlayer (following this pattern: Concrete\Package\{Package Name}\Block\{Block Name}). Note that Block is no plural.

Add a refernece to the \Concrete\Core\Block\BlockType\BlockType class to the top of your controller.

use BlockType;

In your package's install() method, install your block using the Concrete\Core\Block\BlockType\BlockType::installBlockType() method.

public function install()
{
    $pkg = parent::install();
    $bt = BlockType::getByHandle('audio_player');
    if (!is_object($bt)) {
        $bt = BlockType::installBlockType('audio_player', $pkg);
    }       
}

That's it!