Skip to content
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

[FrameworkBundle] Allow multiple transitions with the same name #20795

Merged
merged 1 commit into from Dec 26, 2016

Conversation

Padam87
Copy link
Contributor

@Padam87 Padam87 commented Dec 6, 2016

Q A
Branch? 3.2
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #20794
License MIT
Doc PR -

@@ -409,6 +409,8 @@ private function registerWorkflowConfiguration(array $workflows, ContainerBuilde

$transitions = array();
foreach ($workflow['transitions'] as $transitionName => $transition) {
$transitionName = $transition['name'] ?: $transitionName;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should normalise the values in the Configuration class already to ensure that an element with the name key is set.

@nicolas-grekas nicolas-grekas added this to the 3.2 milestone Dec 7, 2016
@Padam87 Padam87 force-pushed the workflow-framework-bundle-fix branch 2 times, most recently from 4a787f3 to d448322 Compare December 7, 2016 14:03
@nicolas-grekas
Copy link
Member

ping @lyrixx

->isRequired()
->requiresAtLeastOneElement()
->prototype('array')
->children()
->scalarNode('name')->defaultNull()->end()
Copy link
Member

@lyrixx lyrixx Dec 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

->scalarNode('name')
    ->isRequired()
    ->cannotBeEmpty()
->end()

@@ -322,6 +322,14 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
->end()
->end()
->end()
->validate()
Copy link
Member

@lyrixx lyrixx Dec 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

->beforeNormalization()
    ->always()
    ->then(function ($transitions) {
        // It's an indexed array, we let the validation occurs
        if (isset($transitions[0])) {
            return $transitions;
        }

        foreach ($transitions as $name => $transition) {
            if (array_key_exists('name', $transition)) {
                continue;
            }
            $transition['name'] = $name;
            $transitions[$name] = $transition;
        }

        return $transitions;
    })
->end()

@lyrixx
Copy link
Member

lyrixx commented Dec 13, 2016

Hello @Padam87

Thanks for your PR. I added 2 comments about the code. Could you please update your code with my patch?

BTW, with my patch, there is no need to use a key anymore. All the following syntax works:

transitions:
    request_review:
        from: draft
        to:
            - wait_for_journalist
            - wait_for_spellchecker

or

transitions:
    request_review:
        from: draft
        to:
            - wait_for_journalist
            - wait_for_spellchecker
        name: this is the new name, it override request_review

or

transitions:
    -
        from: draft
        to:
            - wait_for_journalist
            - wait_for_spellchecker
        name: here I MUST specify a name

@stof
Copy link
Member

stof commented Dec 13, 2016

We should still validate that you don't have 2 transitions with the same name and a common from node though.

@stof stof changed the title [FrameworkBundle] Allow multiple transactions with the same name [FrameworkBundle] Allow multiple transitions with the same name Dec 13, 2016
@lyrixx
Copy link
Member

lyrixx commented Dec 13, 2016

We should still validate that you don't have 2 transitions with the same name

Yes, indeed

and a common from node though.

Why? it's possible to have 2 transitions, with the same "from" name.

@stof
Copy link
Member

stof commented Dec 13, 2016

@lyrixx your Yes indeed being in the middle of the and qualifying transitions makes me think that you misunderstood my comment entirely (your Yes indeed looks like you want to forbid exactly what this PR is about allowing to configure)

@lyrixx
Copy link
Member

lyrixx commented Dec 13, 2016

Oups, yes, you are right ;) Sorry.

@lyrixx
Copy link
Member

lyrixx commented Dec 13, 2016

But i'm not sure we should validate the "name + from" here. It should be done in the symfony/component validator instead.

@stof
Copy link
Member

stof commented Dec 13, 2016

@lyrixx it indeed must be done in the workflow validator.
But it would not be bad to have an early validation in the DI class if it is easy to do (forbidding to configure an invalid workflow which would fail only later on). Validation during the compile time of the container would give early feedback without performance impact at runtime (as it happens at build time).

@lyrixx
Copy link
Member

lyrixx commented Dec 13, 2016

@stof All validations are already done in a compiler pass ;)

@stof
Copy link
Member

stof commented Dec 13, 2016

then fine. I forgot that

@lyrixx
Copy link
Member

lyrixx commented Dec 26, 2016

Hello @Padam87

I'm sorry, I totally forgot this PR because it was not tagged with Workflow.

Thanks for this PR!

👍

@fabpot
Copy link
Member

fabpot commented Dec 26, 2016

Thank you @Padam87.

@fabpot fabpot merged commit 7c86e16 into symfony:3.2 Dec 26, 2016
fabpot added a commit that referenced this pull request Dec 26, 2016
… name (Padam87)

This PR was merged into the 3.2 branch.

Discussion
----------

[FrameworkBundle] Allow multiple transitions with the same name

| Q             | A
| ------------- | ---
| Branch?       |  3.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #20794
| License       | MIT
| Doc PR        | -

Commits
-------

7c86e16 [FrameworkBundle] Allow multiple transactions with the same name
@fabpot fabpot mentioned this pull request Jan 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants