Skip to content

Twig function workflow_transition is broken when using TraceableWorkflow #52812

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
taakberg opened this issue Nov 30, 2023 · 1 comment
Closed

Comments

@taakberg
Copy link

Symfony version(s) affected

6.4.0

Description

In dev environment, when using the workflow_transition() (not to be confused with workflow_transactions()) in a twig template to get a specific workflow transition, the following error occurs:

An exception has been thrown during the rendering of a template ("Call to undefined method Symfony\Component\Workflow\Debug\TraceableWorkflow::getEnabledTransition()").

This is due to the TraceableWorkflow, introduced in Symfony 6.4.0 not having the getEnabledTransition method implemented, which is implemented in the 'normal' Workflow class. This method is called from the symfony/twig-bridge/Extension/WorkflowExtension.php file.

The WorkflowInterface, which is implemented by both the Workflow and TraceableWorkflow classes does not contain the getEnabledTransaction method as well.

Note that this isn't an issue in the prod environment, as the TraceableWorkflow isn't used there.

How to reproduce

Have a Symfony application with the workflow component set up, running in dev environment.
Then, call the workflow_transition() function in a twig template and render the page.

Possible Solution

The best solution would be to add the getEnabledTransition method to the WorkflowInterface and implement it in TraceableWorkflow.

However, since workflow_transitions() (plural) does work, a temporary workaround can be instead of:

{% set myTransition = workflow_transition(myWorkflow, 'myTransition') %}

Doing it like this:

{% set myTransition = null %}
{% for transition in workflow_transitions(myWorkflow) %}
    {% if transition.name == 'myTransition' %}
        {% set myTransition = transition %}
    {% endif %}
{% endfor %}

It's not an elegant solution, but it works.

Additional Context

No response

@alexandre-daubois
Copy link
Member

alexandre-daubois commented Nov 30, 2023

I can reproduce, I'll take care of the fix 🙂

nicolas-grekas added a commit that referenced this issue Dec 1, 2023
…ow (alexandre-daubois)

This PR was merged into the 6.4 branch.

Discussion
----------

[Workflow] Add `getEnabledTransition()` to TraceableWorkflow

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #52812
| License       | MIT

I added an annotation to `WorkflowInterface` to not break BC. I think it could deserve an additional `not implementing this method is deprecated since Symfony 7.1` while upmerging (I guess ?).

Added the tests while at it.

Commits
-------

f54bc3a [Workflow] Add `getEnabledTransition()` to TraceableWorkflow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants