繁体   English   中英

如何配置 Symfony 工作流程

[英]How to configure a Symfony workflow

我在Symfony 4.2版本上工作我做了一个Workflow Service,他有三个地方草稿,审阅和发布

我将这行代码添加到 conf/products/framework.yaml 中。 但我不明白代码中的 currentPlace 是什么。 我通过这个例子工作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

但是当我刷新网站时,我收到了这个错误

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

错误

您的 YAML 配置的places部分无效。

它应该如下所示:

places:
    - draft
    - reviewed
    - published

注意减号和项目名称之间的空格

我对其进行了更改,以便从类型中删除引号并删除 arguments 并添加approved_by_admin,现在它可以工作了。

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

我将这段代码添加到 Controller

/**
     * @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);
    }

并添加到实体中

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM