Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
$output->writeln('Moved ' . $content->getName() . ' through transition ' . $transitionName);
}

$versionInfo = $content->getVersionInfo();
$workflowMetadataByVersion = $this->workflowService->loadWorkflowMetadataForVersionInfo($versionInfo, $workflowName);

Check warning on line 67 in code_samples/api/public_php_api/src/Command/WorkflowCommand.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused "$workflowMetadataByVersion" local variable.

See more on https://sonarcloud.io/project/issues?id=ezsystems_developer-documentation&issues=AZ39QiJFp2xk0uG8PvHN&open=AZ39QiJFp2xk0uG8PvHN&pullRequest=3186

return self::SUCCESS;
}
}
25 changes: 16 additions & 9 deletions docs/content_management/workflow/workflow_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Workflow API

You can manage [workflows](workflow.md) with PHP API by using `WorkflowServiceInterface`.
You can manage [workflows](workflow.md) with PHP API by using [`WorkflowServiceInterface`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Workflow-Service-WorkflowServiceInterface.html).

## Workflow service

Expand All @@ -22,36 +22,43 @@

## Getting workflow information

To get information about a specific workflow for a content item, use `WorkflowServiceInterface::loadWorkflowMetadataForContent`:
To get information about a specific workflow for a content item, use [`WorkflowServiceInterface::loadWorkflowMetadataForContent`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Workflow-Service-WorkflowServiceInterface.html#method_loadWorkflowMetadataForContent):

``` php
[[= include_file('code_samples/api/public_php_api/src/Command/WorkflowCommand.php', 53, 57) =]]
[[= include_code('code_samples/api/public_php_api/src/Command/WorkflowCommand.php', 54, 58, remove_indent=True) =]]
```

!!! tip

`marking`, a term from [Symfony Workflow]([[= symfony_doc =]]/components/workflow.html),
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`:
If you already have a [`VersionInfo`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-VersionInfo.html) object, use [`WorkflowServiceInterface::loadWorkflowMetadataForVersionInfo`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Workflow-Service-WorkflowServiceInterface.html#method_loadWorkflowMetadataForVersionInfo) to avoid loading the full [`Content`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Content.html).
This method is more efficient when iterating over draft versions:

``` php
[[= include_file('code_samples/api/public_php_api/src/Command/WorkflowCommand.php', 47, 48) =]]
[[= include_code('code_samples/api/public_php_api/src/Command/WorkflowCommand.php', 66, 67, remove_indent=True) =]]
```

To get a list of all workflows that can be used for a given content item, use [`WorkflowRegistryInterface::getSupportedWorkflows`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Workflow-Registry-WorkflowRegistryInterface.html#method_getSupportedWorkflows):

Check notice on line 43 in docs/content_management/workflow/workflow_api.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/content_management/workflow/workflow_api.md#L43

[Ibexa.Passive] Try to avoid passive tense, when possible.
Raw output
{"message": "[Ibexa.Passive] Try to avoid passive tense, when possible.", "location": {"path": "docs/content_management/workflow/workflow_api.md", "range": {"start": {"line": 43, "column": 41}}}, "severity": "INFO"}

``` php
[[= include_code('code_samples/api/public_php_api/src/Command/WorkflowCommand.php', 48, 48, remove_indent=True) =]]
```

## Applying workflow transitions

To place a content item in a workflow, use `WorkflowService::start`:
To place a content item in a workflow, use [`WorkflowServiceInterface::start`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Workflow-Service-WorkflowServiceInterface.html#method_start):

``` php
[[= include_file('code_samples/api/public_php_api/src/Command/WorkflowCommand.php', 52, 53) =]]
[[= include_code('code_samples/api/public_php_api/src/Command/WorkflowCommand.php', 53, 53, remove_indent=True) =]]
```

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`:
Additionally, you can check if the transition is possible for the given object by using [`WorkflowServiceInterface::can`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Workflow-Service-WorkflowServiceInterface.html#method_can):

Check notice on line 58 in docs/content_management/workflow/workflow_api.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/content_management/workflow/workflow_api.md#L58

[Ibexa.Whether] Consider replacing 'if' with 'whether' for clarity
Raw output
{"message": "[Ibexa.Whether] Consider replacing 'if' with 'whether' for clarity", "location": {"path": "docs/content_management/workflow/workflow_api.md", "range": {"start": {"line": 58, "column": 23}}}, "severity": "INFO"}

``` php
[[= include_file('code_samples/api/public_php_api/src/Command/WorkflowCommand.php', 59, 62) =]] }
[[= include_code('code_samples/api/public_php_api/src/Command/WorkflowCommand.php', 60, 64, remove_indent=True) =]]
```

!!! tip
Expand Down
Loading