Page Default Blocks Not Added When Page Added Programatically
Permalink
I have a page type where the default template has been setup with a composer control. When a page is added through the dashboard, the default blocks are added as expected.
When the page is added programatically, this does not happen. The page's areas are empty
Here's my code
Anybody know why this is happening?
When the page is added programatically, this does not happen. The page's areas are empty
Here's my code
$type = PageType::getByHandle('full'); $page = Page::getByID(1); $params = array( 'cName' => 'My Page', 'cDescription' => 'My Description, ); $newPage = $page->add($type, $params);
Anybody know why this is happening?
it's 8.4.5
The issue seems to be that the page default has a composer control block which is not getting the corresponding block it's linked to added to the page. A regular block e.g. content is added just fine, but I need the pages to work with Composer.
It makes me wonder if there's an entirely different process for adding and then publishing a page draft programmatically in the same manner that Composer would?
The issue seems to be that the page default has a composer control block which is not getting the corresponding block it's linked to added to the page. A regular block e.g. content is added just fine, but I need the pages to work with Composer.
It makes me wonder if there's an entirely different process for adding and then publishing a page draft programmatically in the same manner that Composer would?
It turns out the process for adding a page that must work with Composer is a little different. Once I'd realised it was the Composer Control that was not being added, it made me wonder, and then I found this post
https://www.concrete5.org/community/forums/customizing_c5/add-page-p...
and from that I came up with this:
which worked.
https://www.concrete5.org/community/forums/customizing_c5/add-page-p...
and from that I came up with this:
$th = $this->app->make('helper/text'); /* @var $th \Concrete\Core\Utility\Service\Text */ $pagetype = PageType::getByHandle('our_work'); $template = $pagetype->getPageTypeDefaultPageTemplateObject(); $parent = Page::getByID(1); $params = array( 'cName' => 'My New Page', 'cDescription' => 'New Description', 'cHandle' => $th->urlify('My New Page') ); $newPage = $pagetype->createDraft($template, $user = false); /* @var $newPage Page */ $newPage->setPageDraftTargetParentPageID($parent->getCollectionID()); $newPage->update($params); $saver = $pagetype->getPageTypeSaverObject();
Viewing 15 lines of 18 lines. View entire code block.
which worked.
What version of c5 are you using?