-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Documentation workflow context apply #10751
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
noniagriconomie
wants to merge
1
commit into
symfony:master
from
noniagriconomie:workflow-documentation
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,7 @@ like this: | |
audit_trail: | ||
enabled: true | ||
marking_store: | ||
type: 'multiple_state' # or 'single_state' | ||
type: 'multiple_state' # or 'single_state', 'method' ('method' was added in 4.3) | ||
arguments: | ||
- 'currentPlace' | ||
supports: | ||
|
@@ -127,7 +127,7 @@ like this: | |
'enabled' => true | ||
], | ||
'marking_store' => [ | ||
'type' => 'multiple_state', // or 'single_state' | ||
'type' => 'multiple_state', // or 'single_state', 'method' ('method' was added in 4.3) | ||
'arguments' => ['currentPlace'], | ||
], | ||
'supports' => ['App\Entity\BlogPost'], | ||
|
@@ -167,7 +167,7 @@ As configured, the following property is used by the marking store:: | |
|
||
.. note:: | ||
|
||
The marking store type could be "multiple_state" or "single_state". | ||
The marking store type could be "multiple_state", "single_state" or "method". | ||
A single state marking store does not support a model being on multiple places | ||
at the same time. | ||
|
||
|
@@ -221,11 +221,87 @@ you can get the workflow by injecting the Workflow registry service:: | |
// ... if the transition is not allowed | ||
} | ||
|
||
// Update the currentState on the post passing some contextual data | ||
// to the whole workflow process | ||
try { | ||
$workflow->apply($post, 'publish', [ | ||
'log_comment' => 'My logging comment for the publish transition.', | ||
]); | ||
} catch (TransitionException $exception) { | ||
// ... if the transition is not allowed | ||
} | ||
|
||
// See all the available transitions for the post in the current state | ||
$transitions = $workflow->getEnabledTransitions($post); | ||
} | ||
} | ||
|
||
.. versionadded:: 4.1 | ||
|
||
The :class:`Symfony\\Component\\Workflow\\Exception\\TransitionException` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we Need this versionadded ? @symfony/team-symfony-docs |
||
class was introduced in Symfony 4.1. | ||
|
||
.. versionadded:: 4.1 | ||
|
||
The :method:`Symfony\\Component\\Workflow\\Registry::all` method was | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we Need this versionadded ? @symfony/team-symfony-docs |
||
introduced in Symfony 4.1. | ||
|
||
.. versionadded:: 4.3 | ||
|
||
The :method:`Symfony\\Component\\Workflow\\Workflow::apply` has now a new parameter ``$context`` | ||
that is passed to the :class:`Symfony\\Component\\Workflow\\MarkingStore\\MarkingStoreInterface` | ||
:method:`Symfony\\Component\\Workflow\\MarkingStore\\MarkingStoreInterface::setMarking` method. | ||
|
||
An example of usage with the ``$context`` parameter can be when you need, | ||
in addition of marking your object in its new place, to contextualize this change. | ||
|
||
.. tip:: | ||
|
||
Configure the ``type`` as ``method`` of the ``marking_store`` option to use this feature | ||
without implementing your own marking store. | ||
|
||
You can also use this ``$context`` in your own marking store implementation. | ||
A simple implementation example is when you want to store the place as integer instead of string in your object. | ||
|
||
Lets say your object has a status property, stored as an integer in your storage, and you want to log an optional | ||
comment any time the status changes:: | ||
|
||
// your own implementation class, to define in the configuration "marking_store" | ||
|
||
class ObjectMarkingStore implements MarkingStoreInterface | ||
{ | ||
public function getMarking($subject) | ||
{ | ||
$subject->getStatus(); | ||
// ... | ||
// return a marking | ||
} | ||
|
||
public function setMarking($subject, Marking $marking, array $context); | ||
{ | ||
// ... | ||
$subject->setStatus($newStatus, $context['log_comment'] ?? null); | ||
} | ||
} | ||
|
||
// and in your Object class | ||
|
||
public function getStatus() | ||
{ | ||
return $this->status; | ||
} | ||
|
||
public function setStatus(int $status, ?string $comment = null) | ||
{ | ||
$this->status = $status; | ||
$this->addStatusLogRecord(new StatusLog($this, $comment)); | ||
|
||
return $this; | ||
} | ||
|
||
// the StatusLog class can have a createdAt, a username, | ||
// the new status, and finally your optional comment retrieved from the workflow context. | ||
|
||
Using Events | ||
------------ | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I would reword it:
Symfony creates a service for you automatically....
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.
see e1e4efc :)
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.
Thanks