public function WorkbenchModerationSubscriber::onTransition in Workspace 8
Listener for workbench moderation event transitions.
Parameters
\Drupal\workbench_moderation\Event\WorkbenchModerationTransitionEvent $event: The transition event that just fired.
File
- src/
EventSubscriber/ WorkbenchModerationSubscriber.php, line 50
Class
- WorkbenchModerationSubscriber
- Subscriber for workbench transitions.
Namespace
Drupal\workspace\EventSubscriberCode
public function onTransition(WorkbenchModerationTransitionEvent $event) {
/* @var WorkspaceInterface $entity */
$entity = $event
->getEntity();
if ($entity
->getEntityTypeId() == 'workspace' && $this
->wasDefaultRevision($event)) {
// If there is no upstream to replicate to, abort.
if (!$entity
->get('upstream')->entity) {
drupal_set_message(t('The :source workspace does not have an upstream to replicate to!', [
':source' => $entity
->label(),
]), 'error');
// @todo Should we revert the workspace to its previous state?
return;
}
$log = $this
->mergeWorkspaceToParent($entity);
// Pass the replication status to the logic that triggered the state
// change. This allows, for example, the caller to revert back the
// Workspace's workflow state.
// @see \Drupal\workspace\Entity\Form\WorkspaceForm
drupal_static('publish_workspace_replication_status', (bool) $log
->get('ok')->value);
// Set the previous workflow state in case a revert needs to happen.
// Note: we would not be able to revert back the Workspace's moderation
// state here since the event is triggered within a presave hook.
// @todo Find a way to share the replication pass/fail status besides a static.
drupal_static('publish_workspace_previous_state', $event
->getStateBefore());
}
}