function WorkspaceAssociation::getAssociatedRevisions

Same name in other branches
  1. 9 core/modules/workspaces/src/WorkspaceAssociation.php \Drupal\workspaces\WorkspaceAssociation::getAssociatedRevisions()
  2. 10 core/modules/workspaces/src/WorkspaceAssociation.php \Drupal\workspaces\WorkspaceAssociation::getAssociatedRevisions()
  3. 11.x core/modules/workspaces/src/WorkspaceAssociation.php \Drupal\workspaces\WorkspaceAssociation::getAssociatedRevisions()

Overrides WorkspaceAssociationInterface::getAssociatedRevisions

File

core/modules/workspaces/src/WorkspaceAssociation.php, line 159

Class

WorkspaceAssociation
Provides a class for CRUD operations on workspace associations.

Namespace

Drupal\workspaces

Code

public function getAssociatedRevisions($workspace_id, $entity_type_id, $entity_ids = NULL) {
    
    /** @var \Drupal\Core\Entity\EntityStorageInterface $storage */
    $storage = $this->entityTypeManager
        ->getStorage($entity_type_id);
    // If the entity type is not using core's default entity storage, we can't
    // assume the table mapping layout so we have to return only the latest
    // tracked revisions.
    if (!$storage instanceof SqlContentEntityStorage) {
        return $this->getTrackedEntities($workspace_id, $entity_type_id, $entity_ids)[$entity_type_id];
    }
    $entity_type = $storage->getEntityType();
    $table_mapping = $storage->getTableMapping();
    $workspace_field = $table_mapping->getColumnNames($entity_type->get('revision_metadata_keys')['workspace'])['target_id'];
    $id_field = $table_mapping->getColumnNames($entity_type->getKey('id'))['value'];
    $revision_id_field = $table_mapping->getColumnNames($entity_type->getKey('revision'))['value'];
    $query = $this->database
        ->select($entity_type->getRevisionTable(), 'revision');
    $query->leftJoin($entity_type->getBaseTable(), 'base', "revision.{$id_field} = base.{$id_field}");
    $query->fields('revision', [
        $revision_id_field,
        $id_field,
    ])
        ->condition("revision.{$workspace_field}", $workspace_id)
        ->where("revision.{$revision_id_field} > base.{$revision_id_field}")
        ->orderBy("revision.{$revision_id_field}", 'ASC');
    // Restrict the result to a set of entity ID's if provided.
    if ($entity_ids) {
        $query->condition("revision.{$id_field}", $entity_ids, 'IN');
    }
    return $query->execute()
        ->fetchAllKeyed();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.