Get Named Blocks Content from Page Composer
Permalink
Hi!
I created a custom PageType (News Entry) from scratch where I added fields for the composer with named entities (e.g. "News Content").
After that I could successfully create standard output using a Composer-Block.
But now I want to be able to get the content of "News Content" programmatically for a given Page.
I can use
to get all Blocks on a page.
Using some code I found in the Composer Block I also can identify Composer controls with Custum Labels:
But how can I merge this information to get the content for the control labeled "News Content"?
Thanks for your help!
I created a custom PageType (News Entry) from scratch where I added fields for the composer with named entities (e.g. "News Content").
After that I could successfully create standard output using a Composer-Block.
But now I want to be able to get the content of "News Content" programmatically for a given Page.
I can use
$page->getBlocks()
to get all Blocks on a page.
Using some code I found in the Composer Block I also can identify Composer controls with Custum Labels:
$pt = PageTemplate::getByID($page->getPageTemplateID()); $ptt = PageType::getByID($page->getPageTypeID()); $controls = PageTypeComposerOutputControl::getList($ptt, $pt); foreach($controls as $control) { $fls = PageTypeComposerFormLayoutSetControl::getByID($control->getPageTypeComposerFormLayoutSetControlID()); if($fls->getPageTypeComposerFormLayoutSetControlCustomLabel()) { echo $fls->getPageTypeComposerFormLayoutSetControlCustomLabel(); } }
But how can I merge this information to get the content for the control labeled "News Content"?
Thanks for your help!
Hi maxx2097,
What version of concrete5 are you using?
What version of concrete5 are you using?
Hi!
Im using version 5.7.3.1
Im using version 5.7.3.1
I believe I know what you are asking.
An example, let's say the text area attribute called News Teaser has the handle "news_teaser".
One way to access that attribute value is with getCollectionAttributeValue().
Example:
$c->getCollectionAttributeValue('news_teaser')
An example, let's say the text area attribute called News Teaser has the handle "news_teaser".
One way to access that attribute value is with getCollectionAttributeValue().
Example:
$c->getCollectionAttributeValue('news_teaser')
Unfortunatly its not that simple...
...this is not an attribute, but a block from composer. As I understand the content is copied to a standard block when a page is published.
I found the class handling to get the block when the control is known (\Concrete\Core\Page\Type\Composer\Control\BlockControl), but the relevant function ( getPageTypeComposerControlBlockObject(Page $c)) is protected.
Is there any way to extend this class?
...this is not an attribute, but a block from composer. As I understand the content is copied to a standard block when a page is published.
I found the class handling to get the block when the control is known (\Concrete\Core\Page\Type\Composer\Control\BlockControl), but the relevant function ( getPageTypeComposerControlBlockObject(Page $c)) is protected.
Is there any way to extend this class?
OK... as I could not figure out how to extend the BlockControl class, I managed to succeed using reflection to call the protected method:
Maybe there is a more elegant way, but for the moment it works.
// assuming $page contains a valid page object // get page template and type $pt = PageTemplate::getByID($page->getPageTemplateID()); $ptt = PageType::getByID($page->getPageTypeID()); // get all contrrols $controls = PageTypeComposerOutputControl::getList($ptt, $pt); foreach($controls as $control) { $fls = PageTypeComposerFormLayoutSetControl::getByID($control->getPageTypeComposerFormLayoutSetControlID()); // check if control has custom label if($fls->getPageTypeComposerFormLayoutSetControlCustomLabel() == "News Content") { $bc = $fls->getPageTypeComposerControlObject(); $bc->setPageTypeComposerFormLayoutSetControlObject($fls); // invoke protected function using reflection... $r = new ReflectionMethod('Concrete\Core\Page\Type\Composer\Control\BlockControl', 'getPageTypeComposerControlBlockObject');
Viewing 15 lines of 21 lines. View entire code block.
Maybe there is a more elegant way, but for the moment it works.
How can I achieve this?