diff --git a/core/modules/field/modules/entity_reference/entity_reference.install b/core/modules/field/modules/entity_reference/entity_reference.install index 90c69e7..df98254 100644 --- a/core/modules/field/modules/entity_reference/entity_reference.install +++ b/core/modules/field/modules/entity_reference/entity_reference.install @@ -13,11 +13,17 @@ function entity_reference_field_schema($field) { $schema = array( 'columns' => array( 'target_id' => array( - 'description' => 'The id of the target entity.', + 'description' => 'The ID of the target entity.', 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, ), + 'revision_id' => array( + 'description' => 'The revision ID of the target entity.', + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => FALSE, + ), ), 'indexes' => array( 'target_id' => array('target_id'), diff --git a/core/modules/field/modules/entity_reference/lib/Drupal/entity_reference/Plugin/entity_reference/selection/SelectionBase.php b/core/modules/field/modules/entity_reference/lib/Drupal/entity_reference/Plugin/entity_reference/selection/SelectionBase.php index 2a810ed..b0246fe 100644 --- a/core/modules/field/modules/entity_reference/lib/Drupal/entity_reference/Plugin/entity_reference/selection/SelectionBase.php +++ b/core/modules/field/modules/entity_reference/lib/Drupal/entity_reference/Plugin/entity_reference/selection/SelectionBase.php @@ -257,16 +257,14 @@ protected function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTA $query->condition($entity_info['entity_keys']['label'], $match, $match_operator); } - // @todo // Add entity-access tag. - // $query->addTag($this->field['settings']['target_type'] . '_access'); + $query->addTag($this->field['settings']['target_type'] . '_access'); // Add the Selection handler for // entity_reference_query_entity_reference_alter() - //$query->addTag('entity_reference'); - //$query->addMetaData('field', $this->field); - //$query->addMetaData('entity_reference_selection_handler', $this); - + $query->addTag('entity_reference'); + $query->addMetaData('field', $this->field); + $query->addMetaData('entity_reference_selection_handler', $this); // Add the sort option. if (!empty($this->field['settings']['handler_settings']['sort'])) { diff --git a/core/modules/field/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceFormatterBase.php b/core/modules/field/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceFormatterBase.php index cdfd1b1..2ecaaad 100644 --- a/core/modules/field/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceFormatterBase.php +++ b/core/modules/field/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceFormatterBase.php @@ -26,11 +26,15 @@ */ public function prepareView(array $entities, $langcode, array &$items) { $target_ids = array(); + $revision_ids = array(); // Collect every possible entity attached to any of the entities. foreach ($entities as $id => $entity) { foreach ($items[$id] as $delta => $item) { - if (isset($item['target_id'])) { + if (!empty($item['revision_id'])) { + $revision_ids[] = $item['revision_id']; + } + elseif (!empty($item['target_id'])) { $target_ids[] = $item['target_id']; } } @@ -38,24 +42,35 @@ public function prepareView(array $entities, $langcode, array &$items) { $target_type = $this->field['settings']['target_type']; + $target_entities = array(); + if ($target_ids) { $target_entities = entity_load_multiple($target_type, $target_ids); } - else { - $target_entities = array(); + + if ($revision_ids) { + // We need to load the revisions one by-one. + foreach ($revision_ids as $revision_id) { + $entity = entity_revision_load($target_type, $revision_id); + // Use the revision-ID in the key. + $identifier = $entity->id() . ':' . $revision_id; + $target_entities[$identifier] = $entity; + } } // Iterate through the fieldable entities again to attach the loaded data. foreach ($entities as $id => $entity) { foreach ($items[$id] as $delta => $item) { - $items[$id][$delta]['entity'] = $target_entities[$item['target_id']]; - - if (!isset($target_entities[$item['target_id']])) { + // If we have a revision-ID, the key uses it as-well. + $identifier = !empty($item['revision_id']) ? $item['target_id'] . ':' . $item['revision_id'] : $item['target_id']; + if (!isset($target_entities[$identifier])) { continue; } - $entity = $target_entities[$item['target_id']]; + $items[$id][$delta]['entity'] = $target_entities[$identifier]; + + $entity = $target_entities[$identifier]; // TODO: Improve when we have entity_access(). $entity_access = $target_type == 'node' ? node_access('view', $entity) : TRUE;