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.