diff --git a/entity_workflow.module b/entity_workflow.module index 98871328b59ec4d9557fdd3174c76d9a6200918a..cf4632de8e28e181347b0f9e1a999f967d7ec5da 100644 --- a/entity_workflow.module +++ b/entity_workflow.module @@ -386,7 +386,11 @@ function entity_workflow_field_formatter_info_alter(array &$info) { function entity_workflow_transition(ContentEntityInterface $entity, $workflow_id, $transition_id, $log = '', $context = []) { $context['log'] = $log; - $event = new InitiateTransitionEvent($entity, $workflow_id, $transition_id, $context); + $workflow_field = entity_workflow_get_field($entity, $workflow_id); + $workflow = $workflow_field->getWorkflow(); + $transition = $workflow->getTypePlugin()->getTransition($transition_id); + + $event = new InitiateTransitionEvent($transition, $workflow, $entity, $workflow_field, $context); \Drupal::service('event_dispatcher')->dispatch($event, EntityWorkflowEvents::INITIATE_TRANSITION); } diff --git a/modules/entity_workflow_workspace/src/EventSubscriber/EntityWorkflowWorkspaceEventSubscriber.php b/modules/entity_workflow_workspace/src/EventSubscriber/EntityWorkflowWorkspaceEventSubscriber.php index 323f6a29121316b5aaac595e004f471ff778b101..df707b19e9374ef4603978bdb092d81892fab6fa 100644 --- a/modules/entity_workflow_workspace/src/EventSubscriber/EntityWorkflowWorkspaceEventSubscriber.php +++ b/modules/entity_workflow_workspace/src/EventSubscriber/EntityWorkflowWorkspaceEventSubscriber.php @@ -32,17 +32,20 @@ class EntityWorkflowWorkspaceEventSubscriber implements EventSubscriberInterface * The initiate transition event. */ public function onInitiateTransaction(InitiateTransitionEvent $event) { - if ($event->getWorkflowId() === 'workspace') { + if ($event->getWorkflow()->id() === 'workspace') { /** @var \Drupal\workspaces\WorkspaceInterface $workspace */ $workspace = $event->getEntity(); - if ($event->getTransitionId() === 'publish') { + // Workspace publishing must be executed for any transition that goes to + // the 'published' state. + if ($event->getTransition()->to()->id() === 'published') { $workspace->publish(); // @todo When the workspace publisher will invoke a post publish event, // execute the workflow transition there and stop propagating this event. } - if ($event->getTransitionId() === 'unpublish') { + // Workspace reverting is tied to our specific 'unpublish' transition ID. + if ($event->getTransition()->id() === 'unpublish') { \Drupal::service('wse.workspace_reverter')->revert($workspace); } } diff --git a/src/Event/InitiateTransitionEvent.php b/src/Event/InitiateTransitionEvent.php index 4337af13734e7d19380ac9dc1f2fef5ea2fc9620..2ab5506b4341b8b09a65fd2176e82b5e70c03657 100644 --- a/src/Event/InitiateTransitionEvent.php +++ b/src/Event/InitiateTransitionEvent.php @@ -2,72 +2,11 @@ namespace Drupal\entity_workflow\Event; -use Drupal\Component\EventDispatcher\Event; -use Drupal\Core\Entity\ContentEntityInterface; - /** * Defines the initiate transition event. * * @see \Drupal\entity_workflow\Event\EntityWorkflowEvents */ -class InitiateTransitionEvent extends Event { - - /** - * @var \Drupal\Core\Entity\ContentEntityInterface - */ - protected $entity; - - /** - * @var string - */ - protected $workflowId; - - /** - * @var string - */ - protected $transitionId; - - /** - * @var array - */ - protected $transitionContext; - - /** - * Constructs a new InitiateTransitionEvent. - */ - public function __construct(ContentEntityInterface $entity, $workflow_id, $transition_id, $context = []) { - $this->entity = $entity; - $this->workflowId = $workflow_id; - $this->transitionId = $transition_id; - $this->transitionContext = $context; - } - - /** - * @return \Drupal\Core\Entity\ContentEntityInterface - */ - public function getEntity() { - return $this->entity; - } - - /** - * @return string - */ - public function getWorkflowId() { - return $this->workflowId; - } - - /** - * @return string - */ - public function getTransitionId() { - return $this->transitionId; - } - - /** - * @return array - */ - public function getTransitionContext() { - return $this->transitionContext; - } +class InitiateTransitionEvent extends EntityWorkflowTransitionEvent { } diff --git a/src/EventSubscriber/EntityWorkflowEventSubscriber.php b/src/EventSubscriber/EntityWorkflowEventSubscriber.php index 2a1fd85421f579c3ffbb4d5e3c95276063e5d402..1971c50682edaf45a06b36195db42921ae38031c 100644 --- a/src/EventSubscriber/EntityWorkflowEventSubscriber.php +++ b/src/EventSubscriber/EntityWorkflowEventSubscriber.php @@ -47,8 +47,8 @@ class EntityWorkflowEventSubscriber implements EventSubscriberInterface { public function onInitiateTransaction(InitiateTransitionEvent $event) { $entity = $event->getEntity(); - $workflow_field = entity_workflow_get_field($entity, $event->getWorkflowId()); - $workflow_field->applyTransitionById($event->getTransitionId(), $event->getTransitionContext()); + $workflow_field = entity_workflow_get_field($entity, $event->getWorkflow()->id()); + $workflow_field->applyTransition($event->getTransition(), $event->getContext()); $entity->_entityWorkflowEnforceNoNewRevision = TRUE; $entity->save();