@@ -450,3 +450,145 @@ The following example shows these functions in action:
450
450
{% if 'waiting_some_approval' in workflow_marked_places(post) %}
451
451
<span class="label">PENDING</span>
452
452
{% endif %}
453
+
454
+ Storing Metadata
455
+ ----------------
456
+
457
+ .. versionadded :: 4.1
458
+ The feature to store metadata in workflows was introduced in Symfony 4.1.
459
+
460
+ In case you need it, you can store arbitrary metadata in workflows, their
461
+ places, and their transitions using the ``metadata `` option. This metadata can
462
+ be as simple as the title of the workflow or as complex as your own application
463
+ requires:
464
+
465
+ .. configuration-block ::
466
+
467
+ .. code-block :: yaml
468
+
469
+ # config/packages/workflow.yaml
470
+ framework :
471
+ workflows :
472
+ blog_publishing :
473
+ metadata : ' Blog Publishing Workflow'
474
+ # ...
475
+ places :
476
+ draft :
477
+ metadata :
478
+ max_num_of_words : 500
479
+ # ...
480
+ transitions :
481
+ to_review :
482
+ from : draft
483
+ to : review
484
+ metadata :
485
+ priority : 0.5
486
+ # ...
487
+
488
+ .. code-block :: xml
489
+
490
+ <!-- config/packages/workflow.xml -->
491
+ <?xml version =" 1.0" encoding =" utf-8" ?>
492
+ <container xmlns =" http://symfony.com/schema/dic/services"
493
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
494
+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
495
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
496
+ http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd"
497
+ >
498
+
499
+ <framework : config >
500
+ <framework : workflow name =" blog_publishing" type =" workflow" >
501
+ <framework : metadata >
502
+ <framework : title >Blog Publishing Workflow</framework : title >
503
+ </framework : metadata >
504
+ <!-- ... -->
505
+
506
+ <framework : place name =" draft" >
507
+ <framework : metadata >
508
+ <framework : max-num-of-words >500</framework : max-num-of-words >
509
+ </framework : metadata >
510
+ </framework : place >
511
+ <!-- ... -->
512
+
513
+ <framework : transition name =" to_review" >
514
+ <framework : from >draft</framework : from >
515
+ <framework : to >review</framework : to >
516
+ <framework : metadata >
517
+ <framework : priority >0.5</framework : priority >
518
+ </framework : metadata >
519
+ </framework : transition >
520
+ <!-- ... -->
521
+ </framework : workflow >
522
+ </framework : config >
523
+ </container >
524
+
525
+ .. code-block :: php
526
+
527
+ // config/packages/workflow.php
528
+
529
+ $container->loadFromExtension('framework', array(
530
+ // ...
531
+ 'workflows' => array(
532
+ 'blog_publishing' => array(
533
+ 'metadata' => array(
534
+ 'title' => 'Blog Publishing Workflow',
535
+ ),
536
+ // ...
537
+ 'places' => array(
538
+ 'draft' => array(
539
+ 'max_num_of_words' => 500,
540
+ ),
541
+ // ...
542
+ ),
543
+ 'transitions' => array(
544
+ 'to_review' => array(
545
+ 'from' => 'draft',
546
+ 'to' => 'review',
547
+ 'metadata' => array(
548
+ 'priority' => 0.5,
549
+ ),
550
+ ),
551
+ ),
552
+ ),
553
+ ),
554
+ ));
555
+
556
+ Then, you can access this metadata in your PHP code as follows::
557
+
558
+ // MISSING EXAMPLE HERE...
559
+ //
560
+ //
561
+ //
562
+ //
563
+
564
+ In Twig templates, metadata is available via the ``workflow_metadata() `` function:
565
+
566
+ .. code-block :: twig
567
+
568
+ <h2>Metadata</h2>
569
+ <p>
570
+ <strong>Workflow</strong>:<br >
571
+ <code>{{ workflow_metadata(article, 'title') }}</code>
572
+ </p>
573
+ <p>
574
+ <strong>Current place(s)</strong>
575
+ <ul>
576
+ {% for place in workflow_marked_places(article) %}
577
+ <li>
578
+ {{ place }}:
579
+ <code>{{ workflow_metadata(article, 'max_num_of_words', place) ?: 'Unlimited'}}</code>
580
+ </li>
581
+ {% endfor %}
582
+ </ul>
583
+ </p>
584
+ <p>
585
+ <strong>Enabled transition(s)</strong>
586
+ <ul>
587
+ {% for transition in workflow_transitions(article) %}
588
+ <li>
589
+ {{ transition.name }}:
590
+ <code>{{ workflow_metadata(article, 'priority', transition) ?: '0' }}</code>
591
+ </li>
592
+ {% endfor %}
593
+ </ul>
594
+ </p>
0 commit comments