This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Workflow
Fabien Potencier 07a2f6cef4 feature #26092 [Workflow] Add a MetadataStore to fetch some metadata (lyrixx)
This PR was merged into the 4.1-dev branch.

Discussion
----------

[Workflow] Add a MetadataStore to fetch some metadata

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | yes (little)
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #23257
| License       | MIT
| Doc PR        | TODO

---

This is an attempt to fix #23257. I first started to implement
`Ẁorkflow::getMetadata()`, `Transition::getMetadata()` and
`Place::getMetadata()`. **BUT**, there are no `Place` class. For now it's just a
`string`. So dealing with BC is a nightmare.

So I tried to find another way to fix the issue. [This
comment](https://github.com/symfony/symfony/issues/23257#issuecomment-315551397)
summary well the two options. But this PR is (will be) a mix of theses 2
options.

First it will be possible to configure the workflow/metadata like this:

```yaml
blog_publishing:
    supports:
        - AppBundle\Entity\BlogPost
    metada:
         label: Blog publishing
         description: Manages blog publishing
    places:
        draft:
            metadata:
                 description: Blog has just been created
                 color: grey
        review:
            metadata:
                 description: Blog is waiting for review
                 color: blue
    transitions:
        to_review:
            from: draft
            to: review
            metadata:
                label: Submit for review
                route: admin.blog.review
```

I think is very good for the DX. Simple to understand.

All metadata will live in a `MetadataStoreInterface`. If metadata are set via
the configuration (workflows.yaml), then we will use the
`InMemoryMetadataStore`.

Having a MetadataStoreInterface allow user to get dynamic value for a place /
transitions. It's really flexible. (But is it a valid use case ?)

Then, to retrieve these data, the end user will have to write this code:

```php
public function onReview(Event $event) {
    $metadataStore = $event->getWorkflow()->getMetadataStore();
    foreach ($event->getTransition()->getTos() as $place) {
        $this->flashbag->add('info', $metadataStore->getPlaceMetadata($place)->get('description'));
    }
}
```

Note: I might add some shortcut to the Event class

or in twig:

```jinja
{% for transition in workflow_transitions(post) %}
    <a href="{{ workflow_metadata_transition(post, route) }}">
         {{ workflow_metadata_transition(post, transition) }}
   </a>
{% endfor %}
```

---

WDYT ?

Should I continue this way, or should I introduce a `Place` class (there will be
so many deprecation ...)

Commits
-------

bd1f2c8583 [Workflow] Add a MetadataStore
2018-03-21 11:17:02 +01:00
..
DependencyInjection Replace more docblocks by type-hints 2017-11-07 15:45:01 +01:00
Dumper [Workflow] Drop nofooter option in PlantUmlDumper (dead code) 2018-02-09 16:44:04 +01:00
Event feature #26092 [Workflow] Add a MetadataStore to fetch some metadata (lyrixx) 2018-03-21 11:17:02 +01:00
EventListener [Workflow] Cleaned the transition blocker implementations 2018-03-20 19:12:40 +01:00
Exception [Workflow] Cleaned the transition blocker implementations 2018-03-20 19:12:40 +01:00
MarkingStore Replace more docblocks by type-hints 2017-11-07 15:45:01 +01:00
Metadata [Workflow] Add a MetadataStore 2018-03-21 11:06:23 +01:00
SupportStrategy made deprecation notices less verbose 2018-02-19 13:10:10 +01:00
Tests [Workflow] Add a MetadataStore 2018-03-21 11:06:23 +01:00
Validator Replace more docblocks by type-hints 2017-11-07 15:45:01 +01:00
CHANGELOG.md [Workflow] Add a MetadataStore 2018-03-21 11:06:23 +01:00
composer.json Revert "[Workflow] Added the symfony/phpunit-bridge" 2018-02-09 16:09:32 +01:00
Definition.php [Workflow] Add a MetadataStore 2018-03-21 11:06:23 +01:00
DefinitionBuilder.php [Workflow] Remove constraints on transition/place name + Updated Dumper 2018-02-08 10:50:23 +01:00
LICENSE Merge branch '2.8' into 3.3 2018-01-03 18:13:53 +01:00
Marking.php [TwigBridge][Workflow] Fixed code and tests 2017-01-12 19:55:06 +01:00
phpunit.xml.dist Revert "[Workflow] Added the symfony/phpunit-bridge" 2018-02-09 16:09:32 +01:00
README.md [Workflow] update documentation URL in readme 2017-04-05 10:00:23 +02:00
Registry.php made deprecation notices less verbose 2018-02-19 13:10:10 +01:00
StateMachine.php Replace more docblocks by type-hints 2017-11-07 15:45:01 +01:00
Transition.php [Workflow] Remove constraints on transition/place name + Updated Dumper 2018-02-08 10:50:23 +01:00
TransitionBlocker.php [Workflow] Cleaned the transition blocker implementations 2018-03-20 19:12:40 +01:00
TransitionBlockerList.php [Workflow] Cleaned the transition blocker implementations 2018-03-20 19:12:40 +01:00
Workflow.php [Workflow] Add a MetadataStore 2018-03-21 11:06:23 +01:00
WorkflowInterface.php [Workflow] Add a MetadataStore 2018-03-21 11:06:23 +01:00