scopeli/ux-bpmn

BPMN viewer and modeler for Symfony applications

Installs: 130

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:symfony-bundle

v1.0.0 2022-01-06 13:23 UTC

This package is auto-updated.

Last update: 2024-04-06 18:47:46 UTC


README

Total Downloads Daily Downloads UX BPMN

UX BPMN is a Symfony bundle that integrating the bpmn.io library in Symfony applications. It provides a viewer and modeler.

You can checkout the demo for testing.

Installation

UX BPMN requires PHP 7.4.5+ and Symfony 4.4+.

Install this bundle using Composer and Symfony Flex:

composer require scopeli/ux-bpmn

# Don't forget to install the JavaScript dependencies as well and compile
yarn install --force
yarn encore dev

Usage

To use UX BPMN viewer and builder, create the following in PHP:

// ...
use Scopeli\UxBpmn\Model\Modeler;
use Scopeli\UxBpmn\Model\Viewer;

class BpmnController extends AbstractController
{
    const BPMN_FILE = 'example.bpmn';
    
    /**
     * @Route("/show", name="bpmn_show", methods={"GET"}) 
     */
    public function show(): Response
    {    
        return $this->render('bpmn/show.html.twig', [
            'viewer' => new Viewer(Viewer::TYPE_DEFAULT, file_get_contents(self::BPMN_FILE)),
        ]);
    }
    
    /**
     * @Route("/edit", name="bpmn_edit", methods={"GET"}) 
     */
    public function edit(): Response
    {
        $modeler = new Modeler(Modeler::TYPE_DEFAULT, file_get_contents(self::BPMN_FILE));
        $modeler->setConfig([
            'saveUrl' => $this->generateUrl('bpmn_save'),
        ]);
    
        return $this->render('bpmn/edit.html.twig', [
            'modeler' => $modeler,
        ]);
    }
    
    /**
     * @Route("/save", name="bpmn_save", methods={"POST"}) 
     */
    public function save(Request $request): Response
    {
        $data = json_decode($request->getContent());
        
        file_put_contents(self::BPMN_FILE, $data->xml);
        
        return new Response(null, Response::HTTP_NO_CONTENT);
    }
}

After that, you can display the viewer and modeler in Twig (requires Symfony Webpack Encore):

{# bpmn/show.html.twig #}
{{ render_bpmn_viewer(viewer) }}
{# bpmn/edit.html.twig #}
{{ render_bpmn_modeler(modeler) }}