Mercurial > hg > isophonics-drupal-site
diff core/modules/workspaces/src/EntityOperations.php @ 18:af1871eacc83
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:33:08 +0100 |
parents | 129ea1e6d783 |
children |
line wrap: on
line diff
--- a/core/modules/workspaces/src/EntityOperations.php Thu Feb 28 13:21:36 2019 +0000 +++ b/core/modules/workspaces/src/EntityOperations.php Thu May 09 15:33:08 2019 +0100 @@ -57,23 +57,24 @@ } /** - * Acts on entities when loaded. + * Acts on entity IDs before they are loaded. * - * @see hook_entity_load() + * @see hook_entity_preload() */ - public function entityLoad(array &$entities, $entity_type_id) { + public function entityPreload(array $ids, $entity_type_id) { + $entities = []; + // Only run if the entity type can belong to a workspace and we are in a // non-default workspace. if (!$this->workspaceManager->shouldAlterOperations($this->entityTypeManager->getDefinition($entity_type_id))) { - return; + return $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. - $entity_ids = array_keys($entities); $max_revision_id = 'max_target_entity_revision_id'; - $results = $this->entityTypeManager + $query = $this->entityTypeManager ->getStorage('workspace_association') ->getAggregateQuery() ->accessCheck(FALSE) @@ -81,22 +82,14 @@ ->aggregate('target_entity_revision_id', 'MAX', NULL, $max_revision_id) ->groupBy('target_entity_id') ->condition('target_entity_type_id', $entity_type_id) - ->condition('target_entity_id', $entity_ids, 'IN') - ->condition('workspace', $this->workspaceManager->getActiveWorkspace()->id()) - ->execute(); + ->condition('workspace', $this->workspaceManager->getActiveWorkspace()->id()); - // Since hook_entity_load() is called on both regular entity load as well as - // entity revision load, we need to prevent infinite recursion by checking - // whether the default revisions were already swapped with the workspace - // revision. - // @todo This recursion protection should be removed when - // https://www.drupal.org/project/drupal/issues/2928888 is resolved. - if ($results) { - $results = array_filter($results, function ($result) use ($entities, $max_revision_id) { - return $entities[$result['target_entity_id']]->getRevisionId() != $result[$max_revision_id]; - }); + if ($ids) { + $query->condition('target_entity_id', $ids, 'IN'); } + $results = $query->execute(); + if ($results) { /** @var \Drupal\Core\Entity\RevisionableStorageInterface $storage */ $storage = $this->entityTypeManager->getStorage($entity_type_id); @@ -108,6 +101,8 @@ $entities[$revision->id()] = $revision; } } + + return $entities; } /** @@ -133,8 +128,8 @@ throw new \RuntimeException('This entity can only be saved in the default workspace.'); } - /** @var \Drupal\Core\Entity\RevisionableInterface|\Drupal\Core\Entity\EntityPublishedInterface $entity */ - if (!$entity->isNew() && !isset($entity->_isReplicating)) { + /** @var \Drupal\Core\Entity\ContentEntityInterface|\Drupal\Core\Entity\EntityPublishedInterface $entity */ + if (!$entity->isNew() && !$entity->isSyncing()) { // Force a new revision if the entity is not replicating. $entity->setNewRevision(TRUE); @@ -250,11 +245,10 @@ * the new information. Otherwise, a new WorkspaceAssociation entity is created to * store the passed-in entity's information. * - * @param \Drupal\Core\Entity\EntityInterface $entity + * @param \Drupal\Core\Entity\RevisionableInterface $entity * The entity to update or create from. */ - protected function trackEntity(EntityInterface $entity) { - /** @var \Drupal\Core\Entity\RevisionableInterface|\Drupal\Core\Entity\EntityPublishedInterface $entity */ + protected function trackEntity(RevisionableInterface $entity) { // If the entity is not new, check if there's an existing // WorkspaceAssociation entity for it. $workspace_association_storage = $this->entityTypeManager->getStorage('workspace_association');