Skip to content

Documented the workflow metadata #9476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

javiereguiluz
Copy link
Member

This fixes #9475 but it's missing an example. Maybe @lyrixx can help us here. Thanks!

@javiereguiluz
Copy link
Member Author

@lyrixx we'll need your review/help to finish this PR (hopefully before 4.1 is released in one month). Thank you!

@lyrixx
Copy link
Member

lyrixx commented Apr 25, 2018

OK, I will look at it ASAP

Copy link
Member

@lyrixx lyrixx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we go ;)

I have also done that: https://github.com/lyrixx/SFLive-Paris2016-Workflow/pull/8/files

If you need more help, just ping me ;)


Then, you can access this metadata in your PHP code as follows::

// MISSING EXAMPLE HERE...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can access it in different ways.

If you are using the workflow directly:

// I executed this code in the controller, so basically I'm fetching a Workflow instance
        $workflow = $this->get('workflow.article');

        $workflow
            ->getMetadataStore()
            ->getWorkflowMetadata()['title'] ?? false
        ;

        $workflow
            ->getMetadataStore()
            ->getPlaceMetadata('draft')['title'] ?? false
        ;

        $aTransition = $workflow->getDefinition()->getTransitions()[0];

        $workflow
            ->getMetadataStore()
            ->getTransitionMetadata($aTransition)['title'] ?? false
        ;

// There is a shortcut that work with everything, see https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Workflow/Metadata/MetadataStoreInterface.php#L34-L36

        $workflow
            ->getMetadataStore()
            ->getMetadata('title')
        ;

Use case: Flash message:

            // $transition = ...; (an instance of Transition)
            $title = $this->get('workflow.article')->getMetadataStore()->getMetadata('title', $transition);
            $request->getSession()->getFlashBag()->add('info', "You have successfully applied the transition with title: '$title'");

In a listener:

<?php

namespace App\Listener\Workflow\Task;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Workflow\Event\GuardEvent;
use Symfony\Component\Workflow\TransitionBlocker;

class DoneGuard implements EventSubscriberInterface
{
    public function guardPublish(GuardEvent $event)
    {
        $timeLimit = $event->getMetadata('time_limit', $event->getTransition());

        if (date('Hi') <= $timeLimit) {
            return;
        }

        $explanation = $event->getMetadata('explaination', $event->getTransition());
        $event->addTransitionBlocker(new TransitionBlocker($explanation , 0));
    }

    public static function getSubscribedEvents()
    {
        return [
            'workflow.task.guard.done' => 'guardPublish',
        ];
    }
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice snippets :)

{% for transition in workflow_transitions(article) %}
<li>
{{ transition.name }}:
<code>{{ workflow_metadata(article, 'priority', transition) ?: '0' }}</code>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super example !!!

@xabbuh xabbuh changed the base branch from master to 4.1 May 8, 2018 08:40
@alexislefebvre
Copy link
Contributor

Is this PR ready? Can someone please merge it? Can we help in any way?

@lyrixx
Copy link
Member

lyrixx commented Dec 14, 2018

Is this PR ready? Can someone please merge it? Can we help in any way?

No, There is still a "MISSING EXAMPLE HERE".
If you want you can finish it ❤️

@alexislefebvre
Copy link
Contributor

Ok, I'm sorry I thought that your comment filled this gap.

// ...
'places' => array(
'draft' => array(
'max_num_of_words' => 500,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing metadata array or i miss something? @javiereguiluz

fabpot added a commit to symfony/symfony that referenced this pull request Mar 19, 2019
This PR was squashed before being merged into the 4.3-dev branch (closes #29538).

Discussion
----------

[Workflow] Add colors to workflow dumps

Fixes #28874

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #28874, replaces #28933
| License       | MIT
| Doc PR        | TODO, requires symfony/symfony-docs#9476

Fetch data with the `MetadataStore` from #26092 in order to add colors to the dumps.

Example of configuration:

```yaml
            transitions:
                submit:
                    from: start
                    to: travis
                    metadata:
                        title: transition submit title
                        dump_style:
                            label: 'My custom label'
                            arrow_color: '#0088FF'
                            label_color: 'Red'
```

This code was developed as a bundle, examples can be found on its repository: https://github.com/alexislefebvre/SymfonyWorkflowStyleBundle

Commits
-------

60ad109 [Workflow] Add colors to workflow dumps
pbowyer added a commit to pbowyer/symfony-docs that referenced this pull request Mar 23, 2019
pbowyer added a commit to pbowyer/symfony-docs that referenced this pull request Mar 23, 2019
@javiereguiluz
Copy link
Member Author

Closing this in favor of the new PRs created by @pbowyer. Thanks Peter!

pbowyer added a commit to pbowyer/symfony-docs that referenced this pull request Apr 7, 2019
pbowyer added a commit to pbowyer/symfony-docs that referenced this pull request Apr 7, 2019
javiereguiluz added a commit that referenced this pull request Apr 17, 2019
… pbowyer, OskarStark)

This PR was merged into the 4.2 branch.

Discussion
----------

Documented the workflow metadata [redux]

With @javiereguiluz's permission I have taken #9476 and incorporated the comments and code examples into it.

This is the start of a push to improve the Workflow documentation. The focus now is on expanding the documentation by merging pull requests; organizing it will come later.

Commits
-------

7f3a0fd Oskar's feedback
a4c23c1 Add blank line between code block and sentence above. Code block was not rendering.
6080aa8 Remove the word 'simple'
3765ddb Change code formatting of PHP snippet per https://github.com/symfony/symfony-docs/pull/11209/files/d57fa38d903175d58d9cfbf63f20e7ced8d2fd01#r268391655
55c9199 Indent PHP block by an additional 4 spaces
225c2fe Apply suggestions from code review
f716e81 Incorporate @OskarStark's feedback
94d17de Simplify the English and turn it into a tip
40fbaf3 Update arrays to use short syntax
ea64992 Incorporate further excellent feedback from @HeahDude
af71c14 Add an introduction as suggested in #11209 (comment)
ca66356 Document how to see all configuration options (see #11209 (comment))
c9ef262 Incorporate @OskarStark's feedback
c595c47 First set of tidy-ups for @HeahDude's feedback.
663639b Incorporate the code examples in #9476 (comment) into the documentation
17eae8c Add missing metadata key, fixing comment by @noniagriconomie on #9476
d68cc99 Documented the workflow metadata
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants