Skip to content

Commit

Permalink
NEW: Workflow support (#43)
Browse files Browse the repository at this point in the history
* Handle non-existent record in elemental page save handler

* NEW: Workflow support
  • Loading branch information
Aaron Carlino authored Sep 9, 2021
1 parent 93f8179 commit 2513bbe
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
22 changes: 22 additions & 0 deletions _config/workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
Name: 'snapshots-workflow'
Only:
moduleexists: 'symbiote/silverstripe-advancedworkflow'
---
Symbiote\AdvancedWorkflow\Actions\PublishItemWorkflowAction:
extensions:
- SilverStripe\Snapshots\Workflow\WorkflowExtension
Symbiote\AdvancedWorkflow\Jobs\WorkflowPublishTargetJob:
extensions:
- SilverStripe\Snapshots\Workflow\WorkflowExtension

SilverStripe\Core\Injector\Injector:
SilverStripe\EventDispatcher\Dispatch\Dispatcher:
properties:
handlers:
unpublish:
on: [ 'workflowComplete.unpublish' ]
handler: '%$SilverStripe\Snapshots\Handler\Form\UnpublishHandler'
publish:
on: [ 'workflowComplete.publish' ]
handler: '%$SilverStripe\Snapshots\Handler\Form\PublishHandler'
3 changes: 3 additions & 0 deletions src/Handler/Elemental/PageSaveHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ protected function createSnapshot(EventContextInterface $context): ?Snapshot
}

$record = $this->getRecordFromContext($context);
if (!$record) {
return null;
}
if (!$record->hasExtension(ElementalAreasExtension::class)) {
return parent::createSnapshot($context);
}
Expand Down
29 changes: 29 additions & 0 deletions src/Workflow/WorkflowExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php


namespace SilverStripe\Snapshots\Workflow;

use SilverStripe\EventDispatcher\Dispatch\Dispatcher;
use SilverStripe\EventDispatcher\Symfony\Event;
use SilverStripe\ORM\DataExtension;
use SilverStripe\ORM\DataObject;

class WorkflowExtension extends DataExtension
{
public function onAfterWorkflowPublish(DataObject $target)
{
$record = DataObject::get_by_id(get_class($target), $target->ID, false);
Dispatcher::singleton()->trigger('workflowComplete', new Event('publish', [
'record' => $record,
]));
}

public function onAfterWorkflowUnpublish(DataObject $target)
{
$record = DataObject::get_by_id(get_class($target), $target->ID, false);
Dispatcher::singleton()->trigger('workflowComplete', new Event('publish', [
'record' => $record,
]));
}

}

0 comments on commit 2513bbe

Please sign in to comment.