diff --git a/core/lib/Drupal/Core/Field/DynamicEntityReferenceFieldItemList.php b/core/lib/Drupal/Core/Field/DynamicEntityReferenceFieldItemList.php index ba7d15b..62d54f1 100644 --- a/core/lib/Drupal/Core/Field/DynamicEntityReferenceFieldItemList.php +++ b/core/lib/Drupal/Core/Field/DynamicEntityReferenceFieldItemList.php @@ -77,12 +77,9 @@ public static function processDefaultValue($default_value, FieldableEntityInterf $entity_uuids = []; foreach ($all_uuids as $target_type => $uuids) { if ($uuids) { - $entity_ids = \Drupal::entityQuery($target_type) - ->condition('uuid', $uuids, 'IN') - ->execute(); $entities = \Drupal::entityManager() ->getStorage($target_type) - ->loadMultiple($entity_ids); + ->loadByProperties(['uuid' => $uuids]); $entity_uuids[$target_type] = []; foreach ($entities as $id => $entity) { $entity_uuids[$target_type][$entity->uuid()] = $id; diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DynamicEntityReferenceItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DynamicEntityReferenceItem.php index 6f8ca1e..563d0d0 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DynamicEntityReferenceItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DynamicEntityReferenceItem.php @@ -40,7 +40,7 @@ class DynamicEntityReferenceItem extends EntityReferenceItem { public static function defaultStorageSettings() { return array( 'exclude_entity_types' => TRUE, - 'entity_type_ids' => array(), + 'entity_type_ids' => [], ); } @@ -48,17 +48,17 @@ public static function defaultStorageSettings() { * {@inheritdoc} */ public static function defaultFieldSettings() { - $default_settings = array(); + $default_settings = []; $labels = \Drupal::entityManager()->getEntityTypeLabels(TRUE); $options = $labels['Content']; // Field storage settings are not accessible here so we are assuming that // all the entity types are referenceable by default. // See https://www.drupal.org/node/2346273#comment-9385179 for more details. foreach (array_keys($options) as $entity_type_id) { - $default_settings[$entity_type_id] = array( + $default_settings[$entity_type_id] = [ 'handler' => 'default', - 'handler_settings' => array(), - ); + 'handler_settings' => [], + ]; } return $default_settings; } diff --git a/core/modules/entity_reference/src/EntityReferenceController.php b/core/modules/entity_reference/src/EntityReferenceController.php index 8b4bd3b..cc81a22 100644 --- a/core/modules/entity_reference/src/EntityReferenceController.php +++ b/core/modules/entity_reference/src/EntityReferenceController.php @@ -81,7 +81,7 @@ public function handleAutocomplete(Request $request, $type, $field_name, $entity $field_definition = $definitions[$field_name]; $access_control_handler = $this->entityManager()->getAccessControlHandler($entity_type); - if ($field_definition->getType() != 'entity_reference' || !$access_control_handler->fieldAccess('edit', $field_definition)) { + if ($field_definition->getType() != 'entity_reference' || !$access_control_handler->fieldAccess('edit', $field_definition, $this->currentUser())) { throw new AccessDeniedHttpException(); } @@ -137,7 +137,7 @@ public function handleDynamicAutocomplete(Request $request, $field_name, $entity /** @var \Drupal\Core\Field\FieldDefinitionInterface $field_definition */ $field_definition = $definitions[$field_name]; $access_control_handler = $this->entityManager()->getAccessControlHandler($entity_type); - if ($field_definition->getType() != 'dynamic_entity_reference' || !$access_control_handler->fieldAccess('edit', $field_definition)) { + if ($field_definition->getType() != 'dynamic_entity_reference' || !$access_control_handler->fieldAccess('edit', $field_definition, $this->currentUser())) { throw new AccessDeniedHttpException(); } diff --git a/core/modules/entity_reference/src/Tests/DynamicEntityReferenceIntegrationTest.php b/core/modules/entity_reference/src/Tests/DynamicEntityReferenceIntegrationTest.php index c12627c..31020d3 100644 --- a/core/modules/entity_reference/src/Tests/DynamicEntityReferenceIntegrationTest.php +++ b/core/modules/entity_reference/src/Tests/DynamicEntityReferenceIntegrationTest.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\String; use Drupal\config\Tests\AssertConfigEntityImportTrait; +use Drupal\Core\Url; use Drupal\field\Entity\FieldConfig; use Drupal\simpletest\WebTestBase; @@ -110,23 +111,35 @@ public function testDynamicEntityTypesAndWidgets() { $this->assertEqual($entity2->dynamic_references->target_type, 'user'); $this->assertEqual($entity2->dynamic_references->entity->id(), $this->webUser->id()); $this->assertEqual($entity2->dynamic_references->entity->label(), $this->webUser->label()); + /* + // Test autocomplete route as if making a completion from entity1. + $autocomplete_route_parameters = array( + 'field_name' => 'dynamic_references', + 'entity_type' => $entity1->getEntityTypeId(), + 'bundle_name' => $entity1->bundle(), + 'entity_id' => $entity1->id(), + 'target_type' => $entity1->getEntityTypeId(), + ); + $route_name = 'entity_reference.dynamic_entity_reference_autocomplete'; + $url = Url::fromRoute($route_name, $autocomplete_route_parameters); + $result = $this->drupalGetJSON($url); + $this->assertResponse(200); - /* - // Test another input of the entity label without a ' (entity_id)' suffix. - $entity_name3 = $this->randomMachineName(); - $edit = array( - 'name[0][value]' => $entity_name3, - 'dynamic_references[0][target_type]' => 'user', - 'dynamic_references[0][target_id]' => $this->webUser->label(), - ); - $this->drupalPostForm($this->entityType . '/add', $edit, t('Save')); - $entity3 = current(entity_load_multiple_by_properties($this->entityType, array('name' => $entity_name3))); - $this->assertEqual($entity3->dynamic_references->target_id, $this->webUser->id()); - $this->assertEqual($entity3->dynamic_references->target_type, 'user'); - $this->assertEqual($entity3->dynamic_references->entity->id(), $this->webUser->id()); - $this->assertEqual($entity3->dynamic_references->entity->label(), $this->webUser->label()); - */ + // Test another input of the entity label without a ' (entity_id)' suffix. + $entity_name3 = $this->randomMachineName(); + $edit = array( + 'name[0][value]' => $entity_name3, + 'dynamic_references[0][target_type]' => 'user', + 'dynamic_references[0][target_id]' => $this->webUser->label(), + ); + $this->drupalPostForm($this->entityType . '/add', $edit, t('Save')); + $entity3 = current(entity_load_multiple_by_properties($this->entityType, array('name' => $entity_name3))); + $this->assertEqual($entity3->dynamic_references->target_id, $this->webUser->id()); + $this->assertEqual($entity3->dynamic_references->target_type, 'user'); + $this->assertEqual($entity3->dynamic_references->entity->id(), $this->webUser->id()); + $this->assertEqual($entity3->dynamic_references->entity->label(), $this->webUser->label()); + */ }