brexis / laravel-workflow

Use the Symfony Workflow component in Laravel
MIT License
281 stars 105 forks source link

Add support for multiple transitions with the same name #5

Closed laurenkt closed 7 years ago

laurenkt commented 7 years ago

This syntax has been included in Symfony since 3.3, but the config syntax in laravel-workflow doesn't support it.

I've added the alternative syntax referenced in symfony/symfony#22558 and updated the tests to cover it. (This also required fixing the tests, as many of them had the same class name and did not function).

The existing syntax should still work fine.

Example config file for new syntax:

<?php

return [
    'notice' => [
        'type'          => 'state_machine',
        'marking_store' => [
            'arguments' => ['status'],
        ],
        'supports'      => ['App\Notice'],
        'places'        => ['draft', 'published', 'rejected'],
        'transitions'   => [
            [
                'name' => 'approve',
                'from' => 'draft',
                'to'   => 'published',
            ],
            [
                'name' => 'reject',
                'from' => 'draft',
                'to'   => 'rejected',
            ],
            [
                'name' => 'edit',
                'from' => 'published',
                'to'   => 'draft',
            ],
            [
                'name' => 'edit',
                'from' => 'rejected',
                'to'   => 'draft',
            ],
        ],
    ]
];

As you can see, two different states can make the 'edit' transition (see diagram below).

notice

To re-iterate, this functionality exists already in Symfony Workflow, this is just to allow it to be used with laravel-workflow.

brexis commented 7 years ago

Nice one thanks for this @laurenkt .