@@ -533,3 +533,145 @@ You can access the message from a Twig template as follows:
533533Don't need a human-readable message? You can still use::
534534
535535    $event->setBlocked('true'); 
536+ 
537+ Storing Metadata
538+ ---------------- 
539+ 
540+ .. versionadded :: 4.1 
541+     The feature to store metadata in workflows was introduced in Symfony 4.1.
542+ 
543+ In case you need it, you can store arbitrary metadata in workflows, their
544+ places, and their transitions using the ``metadata `` option. This metadata can
545+ be as simple as the title of the workflow or as complex as your own application
546+ requires:
547+ 
548+ .. configuration-block ::
549+ 
550+     .. code-block :: yaml 
551+ 
552+         #  config/packages/workflow.yaml 
553+         framework : 
554+             workflows : 
555+                 blog_publishing : 
556+                     metadata : ' Blog Publishing Workflow'  
557+                     #  ... 
558+                     places : 
559+                         draft : 
560+                             metadata : 
561+                                 max_num_of_words : 500  
562+                         #  ... 
563+                     transitions : 
564+                         to_review : 
565+                             from : draft  
566+                             to :   review  
567+                             metadata : 
568+                                 priority : 0.5  
569+                         #  ... 
570+ 
571+ code-block :: xml 
572+ 
573+         <!--  config/packages/workflow.xml -->  
574+         <?xml  version =" 1.0"  encoding =" utf-8"  
575+         <container  xmlns =" http://symfony.com/schema/dic/services"  
576+             xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"  
577+             xmlns : framework =" http://symfony.com/schema/dic/symfony"  
578+             xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd 
579+                 http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd"  
580+         > 
581+ 
582+             <framework : config > 
583+                 <framework : workflow  name =" blog_publishing" type =" workflow"  
584+                     <framework : metadata > 
585+                         <framework : title >Blog Publishing Workflow</framework : title > 
586+                     </framework : metadata > 
587+                     <!--  ... -->  
588+ 
589+                     <framework : place  name =" draft"  
590+                         <framework : metadata > 
591+                             <framework : max-num-of-words >500</framework : max-num-of-words > 
592+                         </framework : metadata > 
593+                     </framework : place > 
594+                     <!--  ... -->  
595+ 
596+                     <framework : transition  name =" to_review"  
597+                         <framework : from >draft</framework : from > 
598+                         <framework : to >review</framework : to > 
599+                         <framework : metadata > 
600+                             <framework : priority >0.5</framework : priority > 
601+                         </framework : metadata > 
602+                     </framework : transition > 
603+                     <!--  ... -->  
604+                 </framework : workflow > 
605+             </framework : config > 
606+         </container > 
607+ 
608+ code-block :: php 
609+ 
610+         // config/packages/workflow.php 
611+ 
612+         $container->loadFromExtension('framework', array( 
613+             // ... 
614+             'workflows' => array( 
615+                 'blog_publishing' => array( 
616+                     'metadata' => array( 
617+                         'title' => 'Blog Publishing Workflow', 
618+                     ), 
619+                     // ... 
620+                     'places' => array( 
621+                         'draft' => array( 
622+                             'max_num_of_words' => 500, 
623+                         ), 
624+                         // ... 
625+                     ), 
626+                     'transitions' => array( 
627+                         'to_review' => array( 
628+                             'from' => 'draft', 
629+                             'to' => 'review', 
630+                             'metadata' => array( 
631+                                 'priority' => 0.5, 
632+                             ), 
633+                          ), 
634+                      ), 
635+                  ), 
636+              ), 
637+          )); 
638+ 
639+ 
640+ 
641+     // MISSING EXAMPLE HERE... 
642+     // 
643+     // 
644+     // 
645+     // 
646+ 
647+ In Twig templates, metadata is available via the ``workflow_metadata() `` function:
648+ 
649+ .. code-block :: twig 
650+ 
651+     <h2>Metadata</h2> 
652+     <p> 
653+         <strong>Workflow</strong>:<br > 
654+         <code>{{ workflow_metadata(article, 'title') }}</code> 
655+     </p> 
656+     <p> 
657+         <strong>Current place(s)</strong> 
658+         <ul> 
659+             {% for place in workflow_marked_places(article) %} 
660+                 <li> 
661+                     {{ place }}: 
662+                     <code>{{ workflow_metadata(article, 'max_num_of_words', place) ?: 'Unlimited'}}</code> 
663+                 </li> 
664+             {% endfor %} 
665+         </ul> 
666+     </p> 
667+     <p> 
668+         <strong>Enabled transition(s)</strong> 
669+         <ul> 
670+             {% for transition in workflow_transitions(article) %} 
671+                 <li> 
672+                     {{ transition.name }}: 
673+                     <code>{{ workflow_metadata(article, 'priority', transition) ?: '0' }}</code> 
674+                 </li> 
675+             {% endfor %} 
676+         </ul> 
677+     </p> 
0 commit comments