8000 Twig function workflow_transition is broken when using TraceableWorkflow · Issue #52812 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Twig function workflow_transition is broken when using TraceableWorkflow #52812
Closed
@taakberg

Description

@taakberg

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0