Skip to content
Snippets Groups Projects

Update transitions to use WorkflowTransitionEvent.

1 file
+ 8
7
Compare changes
  • Side-by-side
  • Inline
@@ -3,7 +3,8 @@
namespace Drupal\workflows_action\EventSubscriber;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\workflows_field\Event;
use Drupal\workflows_field\Event\WorkflowsFieldEvents;
use Drupal\workflows_field\Event\WorkflowTransitionEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -44,20 +45,20 @@ class TransitionEventSubscriber implements EventSubscriberInterface {
/**
* This method is called whenever the pre_transition event is dispatched.
*
* @param \Symfony\Component\EventDispatcher\Event $event
* @param \Drupal\workflows_field\Event\WorkflowTransitionEvent $event
* The transition event.
*/
public function preTransition(Event $event) {
public function preTransition(WorkflowTransitionEvent $event) {
$this->handleTransition($event, 'pre');
}
/**
* This method is called whenever the post_transition event is dispatched.
*
* @param \Symfony\Component\EventDispatcher\Event $event
* @param \Drupal\workflows_field\Event\WorkflowTransitionEvent $event
* The transition event.
*/
public function postTransition(Event $event) {
public function postTransition(WorkflowTransitionEvent $event) {
$this->handleTransition($event, 'post');
}
@@ -69,7 +70,7 @@ class TransitionEventSubscriber implements EventSubscriberInterface {
* @param string $event_type
* An event type, either 'pre' or 'post'.
*/
protected function handleTransition(Event $event, string $event_type) {
protected function handleTransition(WorkflowTransitionEvent $event, string $event_type) {
$workflow = $event->getWorkflow();
$workflow_actions = $this->entityTypeManager
->getStorage('workflow_action')
@@ -80,7 +81,7 @@ class TransitionEventSubscriber implements EventSubscriberInterface {
$action_storage = $this->entityTypeManager->getStorage('action');
$entities = [];
// If it's a transition event, it can carry an entity.
if ($event instanceof TransitionEventInterface) {
if ($event instanceof WorkflowTransitionEvent) {
$entities[] = $event->getEntity();
}
$transition_id = $event->getTransition()->id();
Loading