Add page programmatically to workflow (or composer)

Permalink 1 user found helpful
Hi everybody,

I have configured a basic workflow and when I add a page in the sitemap of the specified type it appears in "waiting for me" in the dashboard - so the workflow is working fine.

When I create the page of the same page type programmatically in php, it doesn't appear in "waiting for me", only in the sitemap. There, I see no difference between the page created manually and the page created programmatically.
Have you any idea what the difference is and how to achieve that programmatically created pages appear in the workflow?

Alternatively, I want to create a page programmatically to appear as composer draft - therefore I haven't found any hints in the forum, too.

Would be glad if someone could help me with one or both of these problems. Thank you very much!

View Replies:
Ingmar replied on at Permalink Reply
Ok, I've searched some hours in the core functionality of concrete5 and found the solution there.

//Get CollectionType for Composer
$ct = CollectionType::getByHandle('right_sidebar');
//Create a Composer Draft
$pData = array('cName' => 'An automatic Composer-Site');
$entry = ComposerPage::createDraft($ct);
//Stop here when you want to have a composter draft - when you want to add it to the workflow, go ahead

//This code is from /concrete/core/controllers/single_pages/dashboard/composer/write.php
if ($ct->getCollectionTypeComposerPublishMethod() == 'CHOOSE' || $ct->getCollectionTypeComposerPublishMethod() == 'PAGE_TYPE') {
      $parent = Page::getByID($entry->getComposerDraftPublishParentID());
        } else if ($ct->getCollectionTypeComposerPublishMethod() == 'PARENT') {
      $parent = Page::getByID($ct->getCollectionTypeComposerPublishPageParentID());
$v = CollectionVersion::get($entry, 'RECENT');
$pkr = new ApprovePagePageWorkflowRequest();

Events::fire('on_composer_publish', $entry);

The first part creates the composer draft, the second part send it to the workflow, so that it appears in "waiting for me" in the dashboard an vanishes again from composer drafts.
goldhat replied on at Permalink Reply
This is interesting, glad you figured it out. Maybe you can write a How To on it. Would you mind if I added the code to my snippets collection at ?
Ingmar replied on at Permalink Reply
Sure you can use it - lot's of entries in this forum helped me in the past, so I'm happy if I can help others with this one, too.
Ingmar replied on at Permalink Reply
I try to update this v5.6 code to v8.2 now - without luck.
There is no class ComposerPage any more and no dokumentation how to do this now.

When I add a composer page in the sitemap, I see it in "Waiting for me" in the dashboard. I tried to take the same code fragment, but with the following code the page is generated and published at the correct path, but is not in the workflow (and without a title).

//code similar to /dialogs/page/add/compose/submit
$pagetype = PageType::getByHandle($handlename);
$parent = Page::getByPath($path);
$template = $pagetype->getPageTypeDefaultPageTemplateObject();
$d = $pagetype->createDraft($template, $u);
$saver = $pagetype->getPageTypeSaverObject();
$publishDateTime = false;
$pagetype->publish($d, $publishDateTime);

Has anybody fount the solution how to add a page programmatically and add it to the workflow in v5.7 or v5.8?

sharadkap replied on at Permalink Reply
Hello guys! Has anyone fixed this for the C5 8.2.1?
I am trying but didnt have any breakthrough yet.
Would love to know if any of you have fixed this.

sharadkap replied on at Permalink Reply
Okay, so I got this working now by using the following code. May be useful for someone in need of this. I can add a blog post for this and will share my link here soon.
$entry = $ct->createDraft($template, $u);
$v = \CollectionVersion::get($entry, 'RECENT');
$pkr = new ApprovePagePageWorkflowRequest();
$ct->publish($entry, $pkr);
Events::fire('on_composer_publish', $entry);