Skip to content
Snippets Groups Projects

Issue #3436645: Fixing outdated entities issue after update to version 1.11

1 file
+ 26
2
Compare changes
  • Side-by-side
  • Inline
@@ -19,12 +19,36 @@ class EntityReferenceRevisionsFieldItemList extends EntityReferenceFieldItemList
* {@inheritdoc}
*/
public function referencedEntities() {
$target_entities = [];
if ($this->isEmpty()) {
return [];
}
// Collect the IDs of existing entities to load, and directly grab the
// "autocreate" entities that are already populated in $item->entity.
$target_entities = $ids = [];
foreach ($this->list as $delta => $item) {
if ($item->entity) {
if ($item->hasNewEntity()) {
$target_entities[$delta] = $item->entity;
}
elseif ($item->target_id !== NULL) {
$ids[$delta] = $item->target_revision_id;
}
}
// Load and add the existing entities.
if ($ids) {
$target_type = $this->getFieldDefinition()->getSetting('target_type');
$storage = \Drupal::entityTypeManager()->getStorage($target_type);
foreach ($ids as $delta => $target_id) {
$entity = $storage->loadRevision($target_id);
if ($entity) {
$target_entities[$delta] = $entity;
}
}
// Ensure the returned array is ordered by deltas.
ksort($target_entities);
}
return $target_entities;
}
Loading