function WorkspaceAssociation::getTrackedEntitiesForListing

Same name and namespace in other branches
  1. 11.x core/modules/workspaces/src/WorkspaceAssociation.php \Drupal\workspaces\WorkspaceAssociation::getTrackedEntitiesForListing()

Retrieves a paged list of entities tracked by a given workspace.

Parameters

string $workspace_id: The ID of the workspace.

int|null $pager_id: (optional) A pager ID. Defaults to NULL.

int|false $limit: (optional) An integer specifying the number of elements per page. If passed a false value (FALSE, 0, NULL), the pager is disabled. Defaults to 50.

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 WorkspaceAssociationInterface::getTrackedEntitiesForListing

File

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

Class

WorkspaceAssociation
Provides a class for CRUD operations on workspace associations.

Namespace

Drupal\workspaces

Code

public function getTrackedEntitiesForListing($workspace_id, ?int $pager_id = NULL, int|false $limit = 50) : array {
  $query = $this->database
    ->select(static::TABLE)
    ->extend(PagerSelectExtender::class)
    ->limit($limit);
  if ($pager_id) {
    $query->element($pager_id);
  }
  $query->fields(static::TABLE, [
    'target_entity_type_id',
    'target_entity_id',
    'target_entity_revision_id',
  ])
    ->orderBy('target_entity_type_id', 'ASC')
    ->orderBy('target_entity_revision_id', 'DESC')
    ->condition('workspace', $workspace_id);
  $tracked_revisions = [];
  foreach ($query->execute() as $record) {
    $tracked_revisions[$record->target_entity_type_id][$record->target_entity_revision_id] = $record->target_entity_id;
  }
  return $tracked_revisions;
}

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