Thanks to visit codestin.com
Credit goes to github.com

Skip to content

workflow_marked_places() doesn't handle property marking_store.property #34092

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
amalricBzh opened this issue Oct 23, 2019 · 4 comments
Closed

Comments

@amalricBzh
Copy link

amalricBzh commented Oct 23, 2019

Symfony version(s) affected: 4.3.5

Description
Calling Twig bridge workflow_marked_places() on a workflow using custom marking_store.property, with an entity which don't have getMarking() getter raise an error.

How to reproduce

  1. Create a workflow with a custom marking field
      supports: App\Entity\MyEntity
      marking_store:
                type: single_state
                property: status
  1. MyEntity has status field with getter and setter:
    /**
     * @var string
     * @ORM\Column(type="string")
     */
    private $status;

    /**
     * @return string
     */
    public function getStatus(): string
    {
        return $this->status;
    }

    /**
     * @param string $status
     * @return MyEntity 
     */
    public function setStatus(string $status): MyEntity 
    {
        $this->status = $status;
        return $this;
    }
  1. In Twig view, call workflow_marked_places
{% for place in workflow_marked_places(oneEntity) %}
    {{ place }}
{% endfor %}

Possible Solution
The bridge try to call getMarking() on my entity instead of getStatus(). If I had a getMarking() in my entity wich give the status field it's OK. But I think I shouldn't have this getter in my entity as I don't have a $marking property...

    /**
     * @return string
     */
    public function getMarking(): string
    {
        return $this->status;
    }

Traces and warning below may help you...

Additional context
The error and trace:

> Symfony\Component\PropertyAccess\Exception\ NoSuchPropertyException

Neither the property "marking" nor one of the methods "getMarking()", "marking()", "isMarking()", "hasMarking()", "__get()" exist and have public access in class "App\Entity\Tud\Transcription".
in vendor/symfony/property-access/PropertyAccessor.php (line 419)
in vendor/symfony/property-access/PropertyAccessor.php->readProperty (line 93)
in vendor/symfony/workflow/MarkingStore/SingleStateMarkingStore.php->getValue (line 46)
in vendor/symfony/workflow/Workflow.php->getMarking (line 55)
in vendor/symfony/twig-bridge/Extension/WorkflowExtension.php->getMarking (line 98)
in var/cache/dev/twig/95/95fbfe4eb42dd8e45d89142d3197a1579c76c4f042676c73aeb29a45c69fade1.php->getMarkedPlaces (line 246)
in vendor/twig/twig/src/Template.php->block_body (line 184)
in var/cache/dev/twig/69/69cea8d72335b574079f91fdfd25b1dc0c169b9258dd1ab7ffe3fde559a0c954.php->displayBlock (line 154) 

The Workflow component throw a deprecation warning:

User Deprecated: "Symfony\Component\Workflow\MarkingStore\SingleStateMarkingStore" is deprecated since Symfony 4.3, use "Symfony\Component\Workflow\MarkingStore\MethodMarkingStore" instead.

@amalricBzh
Copy link
Author

amalricBzh commented Oct 24, 2019

The bug is caused by the workflow configuration : the deprecation warning is not clear (for me) and it is thrown because the configuration key marking_store.type in my example has another value than method.

Replacing

marking_store:
    type: single_state

By

marking_store:
    type: method

makes everything fine : no more deprecation warning, no more getMarking()/setMarking() methods needed.

So I'm not sure this is a bug, but maybe the deprecation message can be more understandable ?

At least documentation must be fixed. The following paragraph is deprecated and does not mention the method type, nor what it means : https://symfony.com/doc/current/workflow.html . Is there a confusion in this paragraph between workflow.type and marking_store.type ?

The marking store type could be "multiple_state" or "single_state". A single state marking store does not support a model being on multiple places at the same time. This means a "workflow" must use a "multiple_state" marking store and a "state_machine" must use a "single_state" marking store. Symfony configures the marking store according to the "type" by default, so it's preferable to not configure it.
A single state marking store uses a string to store the data. A multiple state marking store uses an array to store the data.

@lyrixx
Copy link
Member

lyrixx commented Oct 28, 2019

Hello. Indeed this is an issue with the documentation.

You have 2 options:

The old way:

marking_store:
    type: single_state
    arguments: ['state']

The new way:

marking_store:
    type: method
    property: state

I saw you open a PR in the doc thanks for that 👍

I also fixed another bug in the doc

And I also open a PR to forbid such situation

@lyrixx
Copy link
Member

lyrixx commented Oct 28, 2019

Note: In symfony 5.0, all this confusion will be removed. You can read more about it on the blog

nicolas-grekas added a commit that referenced this issue Oct 28, 2019
…perty' key (lyrixx)

This PR was merged into the 4.3 branch.

Discussion
----------

[Workflow] Made the configuration more robust for the 'property' key

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #34092
| License       | MIT
| Doc PR        |

Commits
-------

0c31ff0 [Workflow] Made the configuration more robust for the 'property' key
@amalricBzh
Copy link
Author

Thank you, it is my first use of this component. I wonder why I didn't use it sooner !

javiereguiluz added a commit to symfony/symfony-docs that referenced this issue Oct 29, 2019
…yrixx)

This PR was merged into the 4.3 branch.

Discussion
----------

[Workflow] Fixed PHP config of workflow marking store

ref symfony/symfony#34092

Commits
-------

019d1f5 [Workflow] Fixed PHP config of workflow marking store
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