summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/modules/entity_reference/entity_reference.module19
-rw-r--r--core/modules/entity_reference/entity_reference.services.yml2
-rw-r--r--core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceAutocomplete.php17
-rw-r--r--core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/SelectionPluginManager.php22
-rw-r--r--core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteTagsWidget.php2
-rw-r--r--core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidget.php2
-rw-r--r--core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php2
-rw-r--r--core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionSortTest.php4
-rw-r--r--core/modules/entity_reference/lib/Drupal/entity_reference/Tests/Views/SelectionTest.php2
9 files changed, 46 insertions, 26 deletions
diff --git a/core/modules/entity_reference/entity_reference.module b/core/modules/entity_reference/entity_reference.module
index 54a7bac..a13d5cd 100644
--- a/core/modules/entity_reference/entity_reference.module
+++ b/core/modules/entity_reference/entity_reference.module
@@ -77,19 +77,6 @@ function entity_reference_field_widget_info_alter(&$info) {
}
/**
- * Gets the selection handler for a given entity_reference field.
- *
- * @return \Drupal\entity_reference\Plugin\Type\Selection\SelectionInterface
- */
-function entity_reference_get_selection_handler(FieldDefinitionInterface $field_definition, EntityInterface $entity = NULL) {
- $options = array(
- 'field_definition' => $field_definition,
- 'entity' => $entity,
- );
- return Drupal::service('plugin.manager.entity_reference.selection')->getInstance($options);
-}
-
-/**
* Implements hook_field_presave().
*
* Create an entity on the fly.
@@ -115,7 +102,7 @@ function entity_reference_field_validate(EntityInterface $entity = NULL, $field,
}
if ($ids) {
- $valid_ids = entity_reference_get_selection_handler($instance, $entity)->validateReferenceableEntities(array_keys($ids));
+ $valid_ids = Drupal::service('plugin.manager.entity_reference.selection')->getSelectionHandler($instance, $entity)->validateReferenceableEntities(array_keys($ids));
$invalid_entities = array_diff_key($ids, array_flip($valid_ids));
if ($invalid_entities) {
@@ -256,7 +243,7 @@ function entity_reference_field_instance_settings_form($field, $instance, $form_
'#attributes' => array('class' => array('entity_reference-settings')),
);
- $handler = entity_reference_get_selection_handler($instance);
+ $handler = Drupal::service('plugin.manager.entity_reference.selection')->getSelectionHandler($instance);
$form['handler']['handler_settings'] += $handler->settingsForm($field, $instance);
return $form;
@@ -353,7 +340,7 @@ function entity_reference_settings_ajax_submit($form, &$form_state) {
* Implements hook_options_list().
*/
function entity_reference_options_list(FieldDefinitionInterface $field_definition, EntityInterface $entity) {
- if (!$options = entity_reference_get_selection_handler($field_definition, $entity)->getReferenceableEntities()) {
+ if (!$options = Drupal::service('plugin.manager.entity_reference.selection')->getSelectionHandler($field_definition, $entity)->getReferenceableEntities()) {
return array();
}
diff --git a/core/modules/entity_reference/entity_reference.services.yml b/core/modules/entity_reference/entity_reference.services.yml
index 91842ca..e06ef88 100644
--- a/core/modules/entity_reference/entity_reference.services.yml
+++ b/core/modules/entity_reference/entity_reference.services.yml
@@ -4,4 +4,4 @@ services:
arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@module_handler']
entity_reference.autocomplete:
class: Drupal\entity_reference\EntityReferenceAutocomplete
- arguments: ['@plugin.manager.entity']
+ arguments: ['@plugin.manager.entity', '@plugin.manager.entity_reference.selection']
diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceAutocomplete.php b/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceAutocomplete.php
index de01c9c..492fa25 100644
--- a/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceAutocomplete.php
+++ b/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceAutocomplete.php
@@ -4,9 +4,11 @@
* @file
* Contains \Drupal\entity_reference/EntityReferenceAutocomplete.
*/
+
namespace Drupal\entity_reference;
use Drupal\Core\Entity\EntityManager;
+use Drupal\entity_reference\Plugin\Type\SelectionPluginManager;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
/**
@@ -22,13 +24,23 @@ class EntityReferenceAutocomplete {
protected $entityManager;
/**
+ * The Entity reference selection handler plugin manager.
+ *
+ * @var \Drupal\entity_reference\Plugin\Type\SelectionPluginManager
+ */
+ protected $selectionHandlerManager;
+
+ /**
* Constructs a EntityReferenceAutocomplete object.
*
* @param \Drupal\Core\Entity\EntityManager $entity_manager
* The entity manager.
+ * @param \Drupal\entity_reference\Plugin\Type\SelectionPluginManager $selection_manager
+ * The Entity reference selection handler plugin manager.
*/
- public function __construct(EntityManager $entity_manager) {
+ public function __construct(EntityManager $entity_manager, SelectionPluginManager $selection_manager) {
$this->entityManager = $entity_manager;
+ $this->selectionHandlerManager = $selection_manager;
}
/**
@@ -60,7 +72,6 @@ class EntityReferenceAutocomplete {
* @see \Drupal\entity_reference\EntityReferenceController
*/
public function getMatches($field, $instance, $entity_type, $entity_id = '', $prefix = '', $string = '') {
- $target_type = $field['settings']['target_type'];
$matches = array();
$entity = NULL;
@@ -70,7 +81,7 @@ class EntityReferenceAutocomplete {
throw new AccessDeniedHttpException();
}
}
- $handler = entity_reference_get_selection_handler($instance, $entity);
+ $handler = $this->selectionHandlerManager->getSelectionHandler($instance, $entity);
if (isset($string)) {
// Get an array of matching entities.
diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/SelectionPluginManager.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/SelectionPluginManager.php
index bce6ebf..11582f2 100644
--- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/SelectionPluginManager.php
+++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/SelectionPluginManager.php
@@ -10,6 +10,8 @@ namespace Drupal\entity_reference\Plugin\Type;
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Component\Plugin\Factory\ReflectionFactory;
use Drupal\Core\Cache\CacheBackendInterface;
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Entity\Field\FieldDefinitionInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Language\LanguageManager;
use Drupal\Core\Plugin\DefaultPluginManager;
@@ -88,4 +90,24 @@ class SelectionPluginManager extends DefaultPluginManager {
return $plugins;
}
+
+ /**
+ * Gets the selection handler for a given entity_reference field.
+ *
+ * @param \Drupal\Core\Entity\Field\FieldDefinitionInterface $field_definition
+ * The field definition for the operation.
+ * @param \Drupal\Core\Entity\EntityInterface $entity
+ * The entity for the operation.
+ *
+ * @return \Drupal\entity_reference\Plugin\Type\Selection\SelectionInterface
+ * The selection plugin.
+ */
+ public function getSelectionHandler(FieldDefinitionInterface $field_definition, EntityInterface $entity = NULL) {
+ $options = array(
+ 'field_definition' => $field_definition,
+ 'entity' => $entity,
+ );
+ return $this->getInstance($options);
+ }
+
}
diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteTagsWidget.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteTagsWidget.php
index 52e082d..6d46c2f 100644
--- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteTagsWidget.php
+++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteTagsWidget.php
@@ -38,7 +38,7 @@ class AutocompleteTagsWidget extends AutocompleteWidgetBase {
public function elementValidate($element, &$form_state, $form) {
$value = array();
// If a value was entered into the autocomplete.
- $handler = entity_reference_get_selection_handler($this->fieldDefinition);
+ $handler = \Drupal::service('plugin.manager.entity_reference.selection')->getSelectionHandler($this->fieldDefinition);
$bundles = entity_get_bundles($this->getFieldSetting('target_type'));
$auto_create = $this->getSelectionHandlerSetting('auto_create');
diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidget.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidget.php
index 3dcbdcc..fb2b575 100644
--- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidget.php
+++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidget.php
@@ -69,7 +69,7 @@ class AutocompleteWidget extends AutocompleteWidgetBase {
else {
// Try to get a match from the input string when the user didn't use the
// autocomplete but filled in a value manually.
- $handler = entity_reference_get_selection_handler($this->fieldDefinition);
+ $handler = \Drupal::service('plugin.manager.entity_reference.selection')->getSelectionHandler($this->fieldDefinition);
$value = $handler->validateAutocompleteInput($element['#value'], $element, $form_state, $form, !$auto_create);
}
diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php
index ba21eea..ebfccca 100644
--- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php
+++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php
@@ -34,7 +34,7 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
}
protected function assertReferenceable(FieldDefinitionInterface $field_definition, $tests, $handler_name) {
- $handler = entity_reference_get_selection_handler($field_definition);
+ $handler = \Drupal::service('plugin.manager.entity_reference.selection')->getSelectionHandler($field_definition);
foreach ($tests as $test) {
foreach ($test['arguments'] as $arguments) {
diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionSortTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionSortTest.php
index 558c1ce..b44c54d 100644
--- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionSortTest.php
+++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionSortTest.php
@@ -121,7 +121,7 @@ class EntityReferenceSelectionSortTest extends WebTestBase {
$normal_user = $this->drupalCreateUser(array('access content'));
$GLOBALS['user'] = $normal_user;
- $handler = entity_reference_get_selection_handler($instance);
+ $handler = $this->container->get('plugin.manager.entity_reference.selection')->getSelectionHandler($instance);
// Not only assert the result, but make sure the keys are sorted as
// expected.
@@ -137,7 +137,7 @@ class EntityReferenceSelectionSortTest extends WebTestBase {
'field' => 'nid',
'direction' => 'ASC',
);
- $handler = entity_reference_get_selection_handler($instance);
+ $handler = $this->container->get('plugin.manager.entity_reference.selection')->getSelectionHandler($instance);
$result = $handler->getReferenceableEntities();
$expected_result = array(
$nodes['published1']->id() => $node_labels['published1'],
diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/Views/SelectionTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/Views/SelectionTest.php
index 01cb776..cad4bd8 100644
--- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/Views/SelectionTest.php
+++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/Views/SelectionTest.php
@@ -70,7 +70,7 @@ class SelectionTest extends WebTestBase {
$instance->save();
// Get values from selection handler.
- $handler = entity_reference_get_selection_handler($instance);
+ $handler = $this->container->get('plugin.manager.entity_reference.selection')->getSelectionHandler($instance);
$result = $handler->getReferenceableEntities();
$success = FALSE;