How to add a Composer Control block to Page Type template programmatically?

Permalink 1 user found helpful
Hi there!

I created a PageType template and Сomposer form options for this template with this code:

$RssParserSettings = $LeaderChannelType->addPageTypeComposerFormLayoutSet("RSS parser block", "Configure RSS parser block options.");
$RssDisplayerControl = new BlockControl();
$RssDisplayerBlock = BlockType::getByHandle('rss_parser');
$RssDisplayerControl->setBlockTypeID($RssDisplayerBlock->getBlockTypeID());
$RssDisplayerControl->setPageTypeComposerControlCustomLabel('RSS Parser block settings');
$RssDisplayerControl->setPageTypeComposerControlDescription('Configure RSS parser block options.');
$RssDisplayerControl->addToPageTypeComposerFormLayoutSet($RssParserSettings);

It works fine after I put the Composer Control block in the page template,
changing the settings for the page template defaults.

So, now when adding a page of this type, I would like to add Composer Control block programmatically to the page template.
Is there any solution for this task?

Thanks, Nick.

brutalnv
 
kenchi09 replied on at Permalink Reply
kenchi09
I was also looking for the same thing.

It would be helpful if you can add Composer Control blocks via code. :(
brutalnv replied on at Permalink Reply
brutalnv
This is it:
$pageType = PageType::getByHandle('your_page_type');
        $template = $pageType->getPageTypeDefaultPageTemplateObject();
        $pageObj = $pageType->getPageTypePageTemplateDefaultPageObject($template);
        $bt = BlockType::getByHandle('your_block_handle');
        $blocks = $pageObj->getBlocks('Main');
        //only install blocks if there's none on there.
        if (count($blocks) < 1) {
            $data = array(
                'block_option_1' => 1,
'block_option_2' => 2
            );
            $pageObj->addBlock($bt, 'Main', $data);
        }