Skip to content

Commit 0affc6b

Browse files
committed
Add an introduction as suggested in symfony#11209 (comment)
When symfony#9465 is finished, link to details on Transition Blockers.
1 parent 60aa8b1 commit 0affc6b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

workflow/usage.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,15 @@ In a Flash message in your Controller::
605605
$title = $workflow->getMetadataStore()->getMetadata('title', $transition);
606606
$this->addFlash('info', "You have successfully applied the transition with title: '$title'");
607607

608-
In a listener, access via the Event::
608+
In a listener, access via the Event
609+
610+
Metadata can also be accessed in a Listener, from the Event object.
611+
612+
The example below uses a new feature introduced in 4.1 called Transition Blockers. These let you
613+
return a user-friendly error message when you stop a transition from happening. In the example we
614+
get this user-friendly message from the Event's metadata, giving you an easy place to manage the
615+
text. This is a contrived example; in production systems you may prefer to use the
616+
:doc:`Translation </components/translation>` component to manage text::
609617

610618
namespace App\Listener\Workflow\Task;
611619

@@ -623,7 +631,7 @@ In a listener, access via the Event::
623631
return;
624632
}
625633

626-
$explanation = $event->getMetadata('explaination', $event->getTransition());
634+
$explanation = $event->getMetadata('explanation', $event->getTransition());
627635
$event->addTransitionBlocker(new TransitionBlocker($explanation , 0));
628636
}
629637

0 commit comments

Comments
 (0)