function WorkspaceTracker::getTrackedEntities

Retrieves the entities tracked by a given workspace.

Parameters

string $workspace_id: The ID of the workspace.

string|null $entity_type_id: (optional) An entity type ID to filter the results by. Defaults to NULL.

int[]|string[]|null $entity_ids: (optional) An array of entity IDs to filter the results by. Defaults to NULL.

Return value

array Returns a multidimensional array where the first level keys are entity type IDs and the values are an array of entity IDs keyed by revision IDs.

Overrides WorkspaceTrackerInterface::getTrackedEntities

1 call to WorkspaceTracker::getTrackedEntities()
WorkspaceTracker::trackEntity in core/modules/workspaces/src/WorkspaceTracker.php
Updates or creates the association for a given entity and a workspace.

File

core/modules/workspaces/src/WorkspaceTracker.php, line 143

Class

WorkspaceTracker
Provides a class for CRUD operations on workspace associations.

Namespace

Drupal\workspaces

Code

public function getTrackedEntities(string $workspace_id, ?string $entity_type_id = NULL, ?array $entity_ids = NULL) : array {
  $query = $this->database
    ->select(static::TABLE);
  $query->fields(static::TABLE, [
    'target_entity_type_id',
    'target_entity_id',
    'target_entity_id_string',
    'target_entity_revision_id',
  ]);
  $query->orderBy('target_entity_revision_id', 'ASC')
    ->condition('workspace', $workspace_id);
  if ($entity_type_id) {
    $query->condition('target_entity_type_id', $entity_type_id, '=');
    if ($entity_ids) {
      $query->condition(static::getIdField($entity_type_id), $entity_ids, 'IN');
    }
  }
  $tracked_revisions = [];
  foreach ($query->execute() as $record) {
    $target_id = $record->{static::getIdField($record->target_entity_type_id)};
    $tracked_revisions[$record->target_entity_type_id][$record->target_entity_revision_id] = $target_id;
  }
  return $tracked_revisions;
}

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