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!

 
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);
$entry->update($pData);
//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
Cache::disableCache();
Cache::disableLocalCache();
if ($ct->getCollectionTypeComposerPublishMethod() == 'CHOOSE' || $ct->getCollectionTypeComposerPublishMethod() == 'PAGE_TYPE') {
      $parent = Page::getByID($entry->getComposerDraftPublishParentID());
        } else if ($ct->getCollectionTypeComposerPublishMethod() == 'PARENT') {
      $parent = Page::getByID($ct->getCollectionTypeComposerPublishPageParentID());
        }
$entry->move($parent);
$v = CollectionVersion::get($entry, 'RECENT');
$pkr = new ApprovePagePageWorkflowRequest();
$pkr->setRequestedPage($entry);
$pkr->setRequestedVersionID($v->getVersionID());
$pkr->setRequesterUserID(1);
$pkr->trigger();

Events::fire('on_composer_publish', $entry);
$entry->markComposerPageAsPublished();


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 athttp://goldhat.ca/snippets/ ?
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);
$d->setPageDraftTargetParentPageID($parent->getCollectionID());
$saver = $pagetype->getPageTypeSaverObject();
$saver->saveForm($d);
$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?

Thanks!
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.

Thanks!
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);
$entry->update($data);
$v = \CollectionVersion::get($entry, 'RECENT');
$pkr = new ApprovePagePageWorkflowRequest();
$pkr->setRequestedPage($entry);
$pkr->setRequestedVersionID($v->getVersionID());
$pkr->setRequesterUserID($userId);
$ct->publish($entry, $pkr);
$pkr->trigger();
Events::fire('on_composer_publish', $entry);