@@ -189,53 +189,79 @@ Each step has three events that are fired in order:
189
189
* An event for the workflow concerned;
190
190
* An event for the workflow concerned with the specific transition or place name.
191
191
192
- The following events are dispatched:
192
+ When a state transition is initiated, the events are dispatched in the following
193
+ order:
193
194
194
- * ``workflow.guard ``
195
- * ``workflow.[workflow name].guard ``
196
- * ``workflow.[workflow name].guard.[transition name] ``
195
+ ``workflow.guard ``
196
+ Validate whether the transition is allowed at all (:ref: `see below <workflow-usage-guard-events >`).
197
+
198
+ The three events being dispatched are:
199
+
200
+ * ``workflow.guard ``
201
+ * ``workflow.[workflow name].guard ``
202
+ * ``workflow.[workflow name].guard.[transition name] ``
203
+
204
+ ``workflow.leave ``
205
+ The object is about to leave a place.
206
+
207
+ The three events being dispatched are:
208
+
209
+ * ``workflow.leave ``
210
+ * ``workflow.[workflow name].leave ``
211
+ * ``workflow.[workflow name].leave.[place name] ``
212
+
213
+ ``workflow.transition ``
214
+ The object is going through this transition.
197
215
198
- * ``workflow.leave ``
199
- * ``workflow.[workflow name].leave ``
200
- * ``workflow.[workflow name].leave.[place name] ``
216
+ The three events being dispatched are:
201
217
202
- * ``workflow.transition ``
203
- * ``workflow.[workflow name].transition ``
204
- * ``workflow.[workflow name].transition.[transition name] ``
218
+ * ``workflow.transition ``
219
+ * ``workflow.[workflow name].transition ``
220
+ * ``workflow.[workflow name].transition.[transition name] ``
205
221
206
- * ``workflow.enter ``
207
- * `` workflow.[workflow name].enter ``
208
- * `` workflow.[workflow name].enter.[place name] ``
222
+ ``workflow.enter ``
223
+ The object entered a new place. This is the first event where the object
224
+ is marked as being in the new place.
209
225
210
- * ``workflow.entered ``
211
- * ``workflow.[workflow name].entered ``
212
- * ``workflow.[workflow name].entered.[place name] ``
226
+ The three events being dispatched are:
213
227
214
- * ``workflow.announce ``
215
- * ``workflow.[workflow name].announce ``
216
- * ``workflow.[workflow name].announce.[transition name] ``
228
+ * ``workflow.enter ``
229
+ * ``workflow.[workflow name].enter ``
230
+ * ``workflow.[workflow name].enter.[place name] ``
217
231
218
- When a state transition is initiated, the events are fired in the following order:
232
+ `` work.flow.entered ``
219
233
220
- - guard: Validate whether the transition is allowed at all (:ref: `see below <workflow-usage-guard-events >`);
221
- - leave: The object is about to leave a place;
222
- - transition: The object is going through this transition;
223
- - enter: The object entered a new place. This is the first event where the object' is marked as being in the new place;
224
- - announce: Triggered once for each workflow that now is available for the object.
234
+ Similar to ``workflow.enter ``, except the marking store is updated before this
235
+ event (making it a good place to flush data in Doctrine).
236
+
237
+ The three events being dispatched are:
238
+
239
+ * ``workflow.entered ``
240
+ * ``workflow.[workflow name].entered ``
241
+ * ``workflow.[workflow name].entered.[place name] ``
242
+
243
+ ``workflow.announce ``
244
+ Triggered once for each workflow that now is available for the object.
245
+
246
+ The three events being dispatched are:
247
+
248
+ * ``workflow.announce ``
249
+ * ``workflow.[workflow name].announce ``
250
+ * ``workflow.[workflow name].announce.[transition name] ``
225
251
226
252
Here is an example how to enable logging for every time a the "blog_publishing" workflow leaves a place::
227
253
228
254
use Psr\Log\LoggerInterface;
229
255
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
230
256
use Symfony\Component\Workflow\Event\Event;
231
-
257
+
232
258
class WorkflowLogger implements EventSubscriberInterface
233
259
{
234
260
public function __construct(LoggerInterface $logger)
235
261
{
236
262
$this->logger = $logger;
237
263
}
238
-
264
+
239
265
public function onLeave(Event $event)
240
266
{
241
267
$this->logger->alert(sprintf(
@@ -246,7 +272,7 @@ Here is an example how to enable logging for every time a the "blog_publishing"
246
272
implode(', ', $event->getTransition()->getTos())
247
273
));
248
274
}
249
-
275
+
250
276
public static function getSubscribedEvents()
251
277
{
252
278
return array(
@@ -257,14 +283,14 @@ Here is an example how to enable logging for every time a the "blog_publishing"
257
283
258
284
.. _workflow-usage-guard-events :
259
285
260
- Guard events
286
+ Guard Events
261
287
~~~~~~~~~~~~
262
288
263
- There are a special kind of events called "Guard events". Their event listeners
264
- are invoked every time a call to ``Workflow::can ``, ``Workflow::apply `` or
289
+ There are a special kind of events called "Guard events". Their event listeners
290
+ are invoked every time a call to ``Workflow::can ``, ``Workflow::apply `` or
265
291
``Workflow::getEnabledTransitions `` is executed. With the guard events you may
266
- add custom logic to decide what transitions that are valid or not. Here is a list
267
- of the guard event names.
292
+ add custom logic to decide what transitions that are valid or not. Here is a list
293
+ of the guard event names.
268
294
269
295
* ``workflow.guard ``
270
296
* ``workflow.[workflow name].guard ``
0 commit comments