Search code examples
phpsymfonyworkflowsymfony4

How to configure a Symfony workflow


I work on Symfony 4.2 version I made an Workflow Service, who has three places draft, reviewed and published

I add to conf/products/framework.yaml this lines of code. But i don't understand what is currentPlace in the code. I worked by this example https://symfony.com/doc/4.2/workflow.html

workflows:
        article_publishing:
            type: 'workflow'
            audit_trail:
                enabled: true
            marking_store:
                type: 'multiple_state'
                arguments:
                    - 'currentPlace'
            supports:
                - App\Entity\Article
            initial_marking: draft
            places:
                -draft
                -reviewed
                -published
            transitions:
                to_review:
                    from: draft
                    to:   reviewed
                publish:
                    from: reviewed
                    to:   published

But when I refresh the site I get this error

   Warning: array_map(): Argument #2 should be an array

Error


Solution

  • I changed it so that I removed the quotes from type and removed the arguments and added approved_by_admin and now it works.

    framework:
      workflows:
        article_publishing:
          type: workflow
          audit_trail: true
          marking_store:
            type: multiple_state
          supports:
            - App\Entity\Article
          places:
            - draft
            - for_review
            - approved_by_admin
            - published
          transitions:
            to_for_review:
              from: draft
              to:   for_review
            to_approved_by_admin:
              from: for_review
              to: approved_by_admin
            to_published:
              from: approved_by_admin
              to:   published
            to_draft:
              from: for_review
              to:   draft
    

    And I add to Controller this code

    /**
         * @Route("/apply-transition/{article}", methods={"POST"})
         */
        public function applyTransition(WorkflowInterface $articleWorkflow, Request $request, Article $article, RouterInterface $router)
        {
            $slug = $article->getCategory()->getSlug();
            try {
                $articleWorkflow->apply($article, $request->request->get('transition'));
                $this->repository->flush();
            } catch (ExceptionInterface $e) {
               echo $e->getMessage();
            }
            $url = $router->generate('app_category_view', ([
                'slug' => $slug,
            ]));
            return new RedirectResponse($url);
    
        }
        /**
         * @Route("/resetMarking/{article}", methods={"POST"})
         */
    
        public function resetMarking(Article $article, RouterInterface $router)
        {
            $slug = $article->getCategory()->getSlug();
            $article->setMarking([]);
            $this->repository->flush();
            $url = $router->generate('app_category_view', ([
                'slug' => $slug,
            ]));
            return new RedirectResponse($url);
        }
    

    And to Entity I add this

    /**
         * @ORM\Column(type="json_array", nullable=true)
         */
        private $marking;
    
        /**
         * @ORM\Column(type="json_array", nullable=true)
         */
        private $transitionContexts;