PHPackages                             yokai/sonata-workflow - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Admin Panels](/categories/admin)
4. /
5. yokai/sonata-workflow

ActiveLibrary[Admin Panels](/categories/admin)

yokai/sonata-workflow
=====================

Integrate Symfony workflow component in Sonata Admin

v0.9.0(8mo ago)23372.9k↓29.3%14[2 issues](https://github.com/yokai-php/sonata-workflow/issues)[2 PRs](https://github.com/yokai-php/sonata-workflow/pulls)MITPHPPHP ^8.0CI passing

Since Mar 23Pushed 5mo ago3 watchersCompare

[ Source](https://github.com/yokai-php/sonata-workflow)[ Packagist](https://packagist.org/packages/yokai/sonata-workflow)[ RSS](/packages/yokai-sonata-workflow/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (24)Used By (0)

Yokai Sonata Workflow
=====================

[](#yokai-sonata-workflow)

[![Tests](https://camo.githubusercontent.com/fdb26f26a8ed88348587a384f062e61c1f6b47136fd116814d65e2d1b7648216/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f796f6b61692d7068702f736f6e6174612d776f726b666c6f772f74657374732e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265266c6162656c3d7465737473)](https://github.com/yokai-php/sonata-workflow/actions)[![Coverage](https://camo.githubusercontent.com/2b22bbdbbe48b2a951b1df5135ff377b71ae0954fb9eeb5f831741aea392390b/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f796f6b61692d7068702f736f6e6174612d776f726b666c6f773f7374796c653d666c61742d737175617265)](https://codecov.io/gh/yokai-php/sonata-workflow)[![Contributors](https://camo.githubusercontent.com/4afe154b92d0f6a5faa3c62761aabab4530d4b63ea43d5d95527ffc600f25fa0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f796f6b61692d7068702f736f6e6174612d776f726b666c6f773f7374796c653d666c61742d737175617265)](https://github.com/yokai-php/sonata-workflow/graphs/contributors)

[![License](https://camo.githubusercontent.com/97700c1ffad4bbba5da5c8a9ba02e9ffbbf98b654d27c13d080d7d1ce94afabd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f796f6b61692f736f6e6174612d776f726b666c6f773f7374796c653d666c61742d737175617265)](https://packagist.org/packages/yokai/sonata-workflow/stats)[![Latest Stable Version](https://camo.githubusercontent.com/835970854fc6163efae55f17f217bdc0ab772e1df76332f90fc42b87c58ab921/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f796f6b61692f736f6e6174612d776f726b666c6f773f7374796c653d666c61742d737175617265)](https://packagist.org/packages/yokai/sonata-workflow)[![Current Unstable Version](https://camo.githubusercontent.com/734534689bba970be5f6d7452f0ff76f7ffb1c7ba692638ad58653f5e070e11c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f796f6b61692f736f6e6174612d776f726b666c6f773f696e636c7564655f70726572656c6561736573267374796c653d666c61742d737175617265)](https://packagist.org/packages/yokai/sonata-workflow)[![Downloads Monthly](https://camo.githubusercontent.com/b77339d23606dc217fd6af73e6e46e65e3a639b80e68f60c5f826716c733c9b6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f796f6b61692f736f6e6174612d776f726b666c6f773f7374796c653d666c61742d737175617265)](https://packagist.org/packages/yokai/sonata-workflow/stats)[![Total Downloads](https://camo.githubusercontent.com/cc38f993cbca3d5edce6581b24f98670b72fc4ac5733666b5aa2a2c882bbd9d9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f796f6b61692f736f6e6174612d776f726b666c6f773f7374796c653d666c61742d737175617265)](https://packagist.org/packages/yokai/sonata-workflow/stats)

Introduction
------------

[](#introduction)

This library add Symfony Workflow component integration within Sonata Admin.

### Features

[](#features)

- add a menu dropdown to your admin detail pages on which you have buttons to apply available transitions
- ship a controller to apply transition
- allow to hook into the apply transition process to show an intermediate page

### Code

[](#code)

- a Sonata Admin [Extension](https://sonata-project.org/bundles/admin/master/doc/reference/extensions.html) : [WorkflowExtension](src/Admin/Extension/WorkflowExtension.php)
- a Controller trait : [WorkflowControllerTrait](src/Controller/WorkflowControllerTrait.php)
- a Controller : [WorkflowController](src/Controller/WorkflowController.php)

Installation
------------

[](#installation)

```
$ composer require yokai/sonata-workflow
```

Configuration
-------------

[](#configuration)

Let say that you have an entity named `PullRequest` that is under workflow and for which you have an admin.

```
# config/packages/workflow.yml
framework:
    workflows:
        pull_request:
            type: state_machine
            marking_store:
                type: state_machine
                property: status
            supports:
                - App\Entity\PullRequest
            places:
                - opened
                - pending_review
                - merged
                - closed
            initial_marking:
                - opened
            transitions:
                start_review:
                    from: opened
                    to:   pending_review
                merge:
                    from: pending_review
                    to:   merged
                close:
                    from: pending_review
                    to:   closed
```

### One extension for everything

[](#one-extension-for-everything)

The extension is usable for many entities and with no configuration.

You only need to create a service for it, configure the controller that will handle the transition action and configure on which admin you want it available.

For instance :

```
# config/packages/sonata_admin.yml
services:
    admin.pull_request:
        class: App\Admin\PullRequestAdmin
        public: true
        arguments: [~, App\Entity\PullRequest, Yokai\SonataWorkflow\Controller\WorkflowController]
        tags:
            - { name: 'sonata.admin', manager_type: orm, label: PullRequest }
    admin.extension.workflow:
        class: Yokai\SonataWorkflow\Admin\Extension\WorkflowExtension
        public: true
        arguments:
            - '@workflow.registry'
    Yokai\SonataWorkflow\Controller\WorkflowController:
        autowire: true
        tags: ['controller.service_arguments']

sonata_admin:
    extensions:
        admin.extension.workflow:
            admins:
                - admin.pull_request
```

> **note**: You may noticed that we also registered the controller `Yokai\SonataWorkflow\Controller\WorkflowController` as a service. It is important, because it needs the workflow registry service to work.

### More specific extension per admin

[](#more-specific-extension-per-admin)

But the extension accepts many options if you wish to customize the behavior.

For instance :

```
# config/packages/sonata_admin.yml
services:
    admin.pull_request:
        class: App\Admin\PullRequestAdmin
        public: true
        arguments: [~, App\Entity\PullRequest, 'Yokai\SonataWorkflow\Controller\WorkflowController']
        tags:
            - { name: 'sonata.admin', manager_type: orm, label: PullRequest }
    admin.extension.pull_request_workflow:
        class: Yokai\SonataWorkflow\Admin\Extension\WorkflowExtension
        public: true
        arguments:
            - '@workflow.registry'
            - render_actions: [show]
              workflow_name: pull_request
              no_transition_label: No transition for pull request
              no_transition_icon: fa fa-times
              dropdown_transitions_label: Pull request transitions
              dropdown_transitions_icon: fa fa-archive
              transitions_default_icon: fa fa-step-forward
              transitions_icons:
                  start_review: fa fa-search
                  merge: fa fa-check
                  close: fa fa-times
    Yokai\SonataWorkflow\Controller\WorkflowController:
        autowire: true
        tags: ['controller.service_arguments']

sonata_admin:
    extensions:
        admin.extension.pull_request_workflow:
            admins:
                - admin.pull_request
```

What are these options ?

- `render_actions` : Admin action names on which the extension should render its menu (defaults to `[show, edit]`)
- `workflow_name` : The name of the Workflow to handle (defaults to `null`)
- `no_transition_display` : Whether or not to display a button when no transition is enabled (defaults to `false`)
- `no_transition_label` : The button label when no transition is enabled (defaults to `workflow_transitions_empty`)
- `no_transition_icon` : The button icon when no transition is enabled (defaults to `fa fa-code-fork`)
- `dropdown_transitions_label` : The dropdown button label when there is transitions enabled (defaults to `workflow_transitions`)
- `dropdown_transitions_icon` : The dropdown button icon when there is transitions enabled (defaults to `fa fa-code-fork`)
- `transitions_default_icon` : The default transition icon for all transition (defaults to `null` : no icon)
- `transitions_icons` : A hash with transition name as key and icon as value (defaults to `[]`)

Hook into the transition process
--------------------------------

[](#hook-into-the-transition-process)

Let say that when you start a review for a pull request, as a user, you will be asked to enter which users are involved in the review.

To achieve this, you will be asked to fill a dedicated form.

You only need to create a custom controller for your entity admin :

```
# config/packages/sonata_admin.yml
services:
    admin.pull_request:
        class: App\Admin\PullRequestAdmin
        public: true
        arguments: [~, App\Entity\PullRequest, App\Admin\Controller\PullRequestController]
        tags:
            - { name: 'sonata.admin', manager_type: orm, label: PullRequest }
```

```
