Skip to content
Snippets Groups Projects

Issue #3132022: Tweak content_moderation_workspace_access() to utilise content_entity_type_id.

Open Issue #3132022: Tweak content_moderation_workspace_access() to utilise content_entity_type_id.
2 files
+ 50
2
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -45,24 +45,39 @@ public function onWorkspacePrePublish(WorkspacePublishEvent $event): void {
@@ -45,24 +45,39 @@ public function onWorkspacePrePublish(WorkspacePublishEvent $event): void {
// Gather a list of moderation states that don't create a default revision.
// Gather a list of moderation states that don't create a default revision.
$workflow_non_default_states = [];
$workflow_non_default_states = [];
 
$relevant_tracked_vids = [];
foreach ($this->entityTypeManager->getStorage('workflow')->loadByProperties(['type' => 'content_moderation']) as $workflow) {
foreach ($this->entityTypeManager->getStorage('workflow')->loadByProperties(['type' => 'content_moderation']) as $workflow) {
/** @var \Drupal\content_moderation\Plugin\WorkflowType\ContentModerationInterface $workflow_type */
/** @var \Drupal\content_moderation\Plugin\WorkflowType\ContentModerationInterface $workflow_type */
$workflow_type = $workflow->getTypePlugin();
$workflow_type = $workflow->getTypePlugin();
// Find all workflows which are moderating entity types of the same type
// Find all workflows which are moderating entity types of the same type
// to those that are tracked by the workspace.
// to those that are tracked by the workspace.
if (array_intersect($workflow_type->getEntityTypes(), array_keys($tracked_revisions))) {
$relevant_entity_type_ids = array_intersect($workflow_type->getEntityTypes(), array_keys($tracked_revisions));
 
if (!empty($relevant_entity_type_ids)) {
 
 
// Gather all revision ids that should be checked for published state in
 
// the content moderation workflow which are tracked in the workspace.
 
// Entity IDs of types that are not moderated are not relevant here.
 
foreach ($relevant_entity_type_ids as $entity_type_id) {
 
$tracked = $this->workspaceAssociation->getTrackedEntities($workspace->id(), $entity_type_id);
 
$relevant_tracked_vids = array_merge(array_keys($tracked[$entity_type_id]), $relevant_tracked_vids);
 
}
 
$workflow_non_default_states[$workflow->id()] = array_filter(array_map(function (ContentModerationState $state) {
$workflow_non_default_states[$workflow->id()] = array_filter(array_map(function (ContentModerationState $state) {
return !$state->isDefaultRevisionState() ? $state->id() : NULL;
return !$state->isDefaultRevisionState() ? $state->id() : NULL;
}, $workflow_type->getStates()));
}, $workflow_type->getStates()));
}
}
}
}
 
if (!$relevant_tracked_vids) {
 
return;
 
}
 
// Check if any revisions that are about to be published are in a
// Check if any revisions that are about to be published are in a
// non-default revision moderation state.
// non-default revision moderation state.
$query = $this->entityTypeManager->getStorage('content_moderation_state')->getQuery()
$query = $this->entityTypeManager->getStorage('content_moderation_state')->getQuery()
->allRevisions()
->allRevisions()
->accessCheck(FALSE);
->accessCheck(FALSE);
$query->condition('content_entity_revision_id', $tracked_revision_ids, 'IN');
$query->condition('content_entity_revision_id', $relevant_tracked_vids, 'IN');
$workflow_condition_group = $query->orConditionGroup();
$workflow_condition_group = $query->orConditionGroup();
foreach ($workflow_non_default_states as $workflow_id => $non_default_states) {
foreach ($workflow_non_default_states as $workflow_id => $non_default_states) {
Loading