diff --git a/workflow/usage.rst b/workflow/usage.rst index 2126a61d701..e6ce666c2b7 100644 --- a/workflow/usage.rst +++ b/workflow/usage.rst @@ -450,3 +450,145 @@ The following example shows these functions in action: {% if 'waiting_some_approval' in workflow_marked_places(post) %} PENDING {% endif %} + +Storing Metadata +---------------- + +.. versionadded:: 4.1 + The feature to store metadata in workflows was introduced in Symfony 4.1. + +In case you need it, you can store arbitrary metadata in workflows, their +places, and their transitions using the ``metadata`` option. This metadata can +be as simple as the title of the workflow or as complex as your own application +requires: + +.. configuration-block:: + + .. code-block:: yaml + + # config/packages/workflow.yaml + framework: + workflows: + blog_publishing: + metadata: 'Blog Publishing Workflow' + # ... + places: + draft: + metadata: + max_num_of_words: 500 + # ... + transitions: + to_review: + from: draft + to: review + metadata: + priority: 0.5 + # ... + + .. code-block:: xml + + + + + + + + + Blog Publishing Workflow + + + + + + 500 + + + + + + draft + review + + 0.5 + + + + + + + + .. code-block:: php + + // config/packages/workflow.php + + $container->loadFromExtension('framework', array( + // ... + 'workflows' => array( + 'blog_publishing' => array( + 'metadata' => array( + 'title' => 'Blog Publishing Workflow', + ), + // ... + 'places' => array( + 'draft' => array( + 'max_num_of_words' => 500, + ), + // ... + ), + 'transitions' => array( + 'to_review' => array( + 'from' => 'draft', + 'to' => 'review', + 'metadata' => array( + 'priority' => 0.5, + ), + ), + ), + ), + ), + )); + +Then, you can access this metadata in your PHP code as follows:: + + // MISSING EXAMPLE HERE... + // + // + // + // + +In Twig templates, metadata is available via the ``workflow_metadata()`` function: + +.. code-block:: twig + +

Metadata

+

+ Workflow:
+ {{ workflow_metadata(article, 'title') }} +

+

+ Current place(s) +

+

+

+ Enabled transition(s) +

+