All Projects → yokai-php → sonata-workflow

yokai-php / sonata-workflow

Licence: MIT License
Integrate Symfony workflow component in Sonata Admin

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to sonata-workflow

alfred-mailto
Send emails to recipients and groups from Alfred
Stars: ✭ 59 (+156.52%)
Mutual labels:  workflow
tumbleweed
Lightweight workflow engine microservice implement BPMN 2.0
Stars: ✭ 23 (+0%)
Mutual labels:  workflow
AlfredWorkflows
My workflow creations for Alfred on macOS.
Stars: ✭ 55 (+139.13%)
Mutual labels:  workflow
cookiecutter-r-data-analysis
cookie cutter template for my r workflow
Stars: ✭ 19 (-17.39%)
Mutual labels:  workflow
monopacker
A tool for managing builds of monorepo frontend projects with eg. npm- or yarn workspaces, lerna or similar tools into a standalone application - no other tools needed.
Stars: ✭ 17 (-26.09%)
Mutual labels:  workflow
simpleflow
Python library for dataflow programming.
Stars: ✭ 67 (+191.3%)
Mutual labels:  workflow
jekyll-deploy-action
🪂 A Github Action to deploy the Jekyll site conveniently for GitHub Pages.
Stars: ✭ 162 (+604.35%)
Mutual labels:  workflow
simple-workflow
Laravel simple implementation of a complete workflow system, allowing you to focus on your business logic and letting the package do the necessary work to make your workflow system work and easy to customize
Stars: ✭ 58 (+152.17%)
Mutual labels:  workflow
drupal9ci
One-line installers for implementing Continuous Integration in Drupal 9
Stars: ✭ 137 (+495.65%)
Mutual labels:  workflow
bistro
A library to build and execute typed scientific workflows
Stars: ✭ 43 (+86.96%)
Mutual labels:  workflow
version-check
An action that allows you to check whether your npm package version has been updated
Stars: ✭ 65 (+182.61%)
Mutual labels:  workflow
alfred-microsoft-onenote-navigator
Use Alfred to browse through your Microsoft OneNote notebooks, section groups and sections and then jump to them instantly.
Stars: ✭ 52 (+126.09%)
Mutual labels:  workflow
bitnami-docker-airflow-scheduler
Bitnami Docker Image for Apache Airflow Scheduler
Stars: ✭ 19 (-17.39%)
Mutual labels:  workflow
benten
A language server for Common Workflow Language
Stars: ✭ 50 (+117.39%)
Mutual labels:  workflow
tip
GitHub Action to keep a 'tip' pre-release always up-to-date
Stars: ✭ 18 (-21.74%)
Mutual labels:  workflow
iSkyLIMS
is an open-source LIMS (laboratory Information Management System) for Next Generation Sequencing sample management, statistics and reports, and bioinformatics analysis service management.
Stars: ✭ 33 (+43.48%)
Mutual labels:  workflow
RWorkflow
📑 My approach to an analysis or product produced with R
Stars: ✭ 25 (+8.7%)
Mutual labels:  workflow
release-notify-action
GitHub Action that triggers e-mails with release notes when these are created
Stars: ✭ 64 (+178.26%)
Mutual labels:  workflow
wakatime-to-toggl
📩 Sync your WakaTime data in Toggl
Stars: ✭ 23 (+0%)
Mutual labels:  workflow
alfred-fanfou
Alfred workflow for Fanfou
Stars: ✭ 15 (-34.78%)
Mutual labels:  workflow

Yokai Sonata Workflow

Tests Coverage Contributors

License Latest Stable Version Current Unstable Version Downloads Monthly Total Downloads

Introduction

This library add Symfony Workflow component integration within Sonata Admin.

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

Installation

$ composer require yokai/sonata-workflow

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

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

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

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 }
<?php
// src/Admin/Controller/PullRequestController.php

declare(strict_types=1);

namespace App\Admin\Controller;

use App\Entity\PullRequest;
use App\Form\PullRequest\StartReviewType;
use Sonata\AdminBundle\Controller\CRUDController;
use Symfony\Component\HttpFoundation\Response;
use Yokai\SonataWorkflow\Controller\WorkflowControllerTrait;

class PullRequestController extends CRUDController
{
    use WorkflowControllerTrait;

    protected function preApplyTransition(object $object, string $transition): ?Response
    {
        switch ($transition) {
            case 'start_review':
                return $this->startReview($object, $transition);
        }

        return null;
    }

    protected function startReview(PullRequest $object, string $transition): ?Response
    {
        $form = $this->createForm(
            StartReviewType::class,
            [],
            [
                'action' => $this->admin->generateObjectUrl(
                    'workflow_apply_transition',
                    $object,
                    ['transition' => $transition]
                ),
            ]
        );

        $form->handleRequest($this->getRequest());

        if (!$form->isSubmitted() || !$form->isValid()) {
            $formView = $form->createView();

            return $this->renderWithExtraParams('admin/pull-request/start-review.html.twig', [
                'action' => 'edit',
                'form' => $formView,
                'object' => $object,
                'objectId' => $this->admin->getNormalizedIdentifier($object),
            ], null);
        }

        $data = $form->getData();
        // do something with the submitted data before returning null to continue applying transition

        return null;
    }
}

MIT License

License can be found here.

Authors

The library was originally created by Yann Eugoné. See the list of contributors.


Thank's to Prestaconcept for supporting this library.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].