Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Document Transition Blockers#11212

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Closed
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletionsworkflow/usage.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -475,3 +475,70 @@ The following example shows these functions in action:
{% if 'waiting_some_approval' in workflow_marked_places(post) %}
<span class="label">PENDING</span>
{% endif %}

Transition Blockers
-------------------

.. versionadded:: 4.1
Transition Blockers were introduced in Symfony 4.1.

Transition Blockers provide a simple way to return a human-readable message for why a transition
was blocked. You can access the message from Twig. Here's an example:


.. code-block:: php

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

class BlogPostPublishListener implements EventSubscriberInterface
{
public function guardPublish(GuardEvent $event)
{
/** @var \App\Entity\BlogPost $post */
$post = $event->getSubject();

// If it's after 9pm, prevent publication
if (date('H') > 21) {
$event->addTransitionBlocker(
new TransitionBlocker(
"You can not publish this blog post because it's too late. Try again tomorrow morning."
)
);
}
}

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

.. code-block:: html+twig

<h2>Publication was blocked because:</h2>
<ul>
{% for transition in workflow_all_transitions(article) %}
{% if not workflow_can(article, transition.name) %}
<li>
<strong>{{ transition.name }}</strong>:
<ul>
{% for blocker in workflow_build_transition_blocker_list(article, transition.name) %}
<li>
{{ blocker.message }}
{% if blocker.parameters.expression is defined %}
<code>{{ blocker.parameters.expression }}</code>
{% endif %}
</li>
{% endfor %}
</ul>
</li>
{% endif %}
{% endfor %}
</ul>

Don't need a human-readable message? You can still use::

$event->setBlocked('true');

[8]ページ先頭

©2009-2025 Movatter.jp