-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Conversation
@lyrixx we'll need your review/help to finish this PR (hopefully before 4.1 is released in one month). Thank you! |
OK, I will look at it ASAP |
There was a problem hiding this 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... |
There was a problem hiding this comment.
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',
];
}
}
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super example !!!
Is this PR ready? Can someone please merge it? Can we help in any way? |
No, There is still a "MISSING EXAMPLE HERE". |
Ok, I'm sorry I thought that your comment filled this gap. |
// ... | ||
'places' => array( | ||
'draft' => array( | ||
'max_num_of_words' => 500, |
There was a problem hiding this comment.
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
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
Closing this in favor of the new PRs created by @pbowyer. Thanks Peter! |
… 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
This fixes #9475 but it's missing an example. Maybe @lyrixx can help us here. Thanks!