function WorkspaceProviderBase::entityPreload
Acts before an entity is loaded.
Parameters
array $ids: An array of entity IDs.
string $entity_type_id: The entity type ID.
Return value
array The modified array of entity IDs.
Overrides WorkspaceProviderInterface::entityPreload
File
-
core/
modules/ workspaces/ src/ Provider/ WorkspaceProviderBase.php, line 91
Class
- WorkspaceProviderBase
- Defines the base class for workspace providers.
Namespace
Drupal\workspaces\ProviderCode
public function entityPreload(array $ids, string $entity_type_id) : array {
$entities = [];
// Get a list of revision IDs for entities that have a revision set for the
// current active workspace. If an entity has multiple revisions set for a
// workspace, only the one with the highest ID is returned.
if ($tracked_entities = $this->workspaceAssociation
->getTrackedEntities($this->workspaceManager
->getActiveWorkspace()
->id(), $entity_type_id, $ids)) {
// Bail out early if there are no tracked entities of this type.
if (!isset($tracked_entities[$entity_type_id])) {
return $entities;
}
/** @var \Drupal\Core\Entity\RevisionableStorageInterface $storage */
$storage = $this->entityTypeManager
->getStorage($entity_type_id);
// Swap out every entity which has a revision set for the current active
// workspace.
foreach ($storage->loadMultipleRevisions(array_keys($tracked_entities[$entity_type_id])) as $revision) {
$entities[$revision->id()] = $revision;
}
}
return $entities;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.