You are here

public function WorkspacePublisher::getDifferringRevisionIdsOnTarget in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/workspaces/src/WorkspacePublisher.php \Drupal\workspaces\WorkspacePublisher::getDifferringRevisionIdsOnTarget()
  2. 10 core/modules/workspaces/src/WorkspacePublisher.php \Drupal\workspaces\WorkspacePublisher::getDifferringRevisionIdsOnTarget()

Gets the revision identifiers for items which have changed on the target.

Return value

array A multidimensional array of revision identifiers, keyed by entity type IDs.

Overrides WorkspaceOperationInterface::getDifferringRevisionIdsOnTarget

1 call to WorkspacePublisher::getDifferringRevisionIdsOnTarget()
WorkspacePublisher::getNumberOfChangesOnTarget in core/modules/workspaces/src/WorkspacePublisher.php
Gets the total number of items which have changed on the target.

File

core/modules/workspaces/src/WorkspacePublisher.php, line 154

Class

WorkspacePublisher
Default implementation of the workspace publisher.

Namespace

Drupal\workspaces

Code

public function getDifferringRevisionIdsOnTarget() {
  $target_revision_difference = [];
  $tracked_entities = $this->workspaceAssociation
    ->getTrackedEntities($this->sourceWorkspace
    ->id());
  foreach ($tracked_entities as $entity_type_id => $tracked_revisions) {
    $entity_type = $this->entityTypeManager
      ->getDefinition($entity_type_id);

    // Get the latest revision IDs for all the entities that are tracked by
    // the source workspace.
    $query = $this->entityTypeManager
      ->getStorage($entity_type_id)
      ->getQuery()
      ->condition($entity_type
      ->getKey('id'), $tracked_revisions, 'IN')
      ->latestRevision();
    $result = $query
      ->execute();

    // Now we compare the revision IDs which are tracked by the source
    // workspace to the latest revision IDs of those entities and the
    // difference between these two arrays gives us all the entities which
    // have been modified on the target.
    if ($revision_difference = array_diff_key($result, $tracked_revisions)) {
      $target_revision_difference[$entity_type_id] = $revision_difference;
    }
  }
  return $target_revision_difference;
}