Skip to content
Snippets Groups Projects
Commit 610424bf authored by Andrei Mateescu's avatar Andrei Mateescu
Browse files

Bring back entity_workflow_has_entity_state().

parent 18bd4555
No related branches found
No related tags found
No related merge requests found
......@@ -505,3 +505,62 @@ function entity_workflow_get_history($entity_type_id, array $entity_ids, $workfl
return $transition_logs;
}
/**
* Check if any of the revisions has a particular workflow state in a workspace.
*
* @param string $workflow_id
* The workflow ID.
* @param string $workspace_id
* The workspace ID.
* @param string $entity_type_id
* The entity type.
* @param array $revision_ids
* The revision IDs.
* @param string $state
* The state.
*
* @return bool
* TRUE if the state was found, FALSE otherwise
*/
function entity_workflow_has_entity_state($workflow_id, $workspace_id, $entity_type_id, array $revision_ids, $state) {
$has_state = \Drupal::service('workspaces.manager')->executeInWorkspace($workspace_id, function () use ($workflow_id, $entity_type_id, $revision_ids, $state) {
$entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id);
$field_name = entity_workflow_get_field_name($workflow_id);
$query = \Drupal::entityTypeManager()->getStorage($entity_type_id)->getQuery();
if ($revision_ids) {
$query->condition($entity_type->getKey('revision'), $revision_ids, 'IN');
}
$query
->condition($field_name, $state)
->accessCheck(FALSE)
->count()
->range(0, 1);
return (bool) $query->execute();
});
return $has_state;
}
/**
* Check if revisions have a workflow state other than the parameter.
*
* @param string $workflow_id
* The workflow ID.
* @param string $workspace_id
* The workspace ID.
* @param string $entity_type_id
* The entity type.
* @param array $revision_ids
* The revision IDs.
* @param string $state
* The state.
*
* @return bool
* TRUE if the state was not found, FALSE otherwise
*/
function entity_workflow_has_not_entity_state($workflow_id, $workspace_id, $entity_type_id, array $revision_ids, $state) {
return !entity_workflow_has_entity_state($workflow_id, $workspace_id, $entity_type_id, $revision_ids, $state);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment