Skip to content

Workflow API

You can manage workflows with PHP API by using WorkflowServiceInterface.

Getting workflow information

To get information about a specific workflow for a Content item, use WorkflowServiceInterface::loadWorkflowMetadataForContent:

1
2
3
4
        $workflowMetadata = $this->workflowService->loadWorkflowMetadataForContent($content, $workflowName);

        foreach ($workflowMetadata->markings as $marking) {
            $output->writeln($content->getName() . ' is in stage ' . $marking->name . ' in workflow ' . $workflowMetadata->workflow->getName());

Tip

marking, a term from Symfony Workflow, refers to a state in a workflow.

To get a list of all workflows that can be used for a given Content item, use WorkflowRegistry:

1
        $supportedWorkflows = $this->workflowRegistry->getSupportedWorkflows($content);

Applying workflow transitions

To place a Content item in a workflow, use WorkflowService::start:

1
        $this->workflowService->start($content, $workflowName);

To apply a transition to a Content item, use Workflow::apply. Additionally, you can check if the transition is possible for the given object using WorkflowService::can:

1
2
3
4
       if ($this->workflowService->can($workflowMetadata, $transitionName)) {
            $workflow = $this->workflowRegistry->getWorkflow($workflowName);
            $workflow->apply($workflowMetadata->content, $transitionName,  ['message' => 'done', 'reviewerId' => 14]);
    }

Tip

Ibexa\Workflow\Value\WorkflowMetadata object contains all information about a workflow, such as ID, name, transitions and current stage. Ibexa\Workflow\Value\WorkflowMetadata::$workflow gives you direct access to native Symfony Workflow object.