diff --git a/core/modules/entity_reference/src/Plugin/Type/SelectionPluginManager.php b/core/modules/entity_reference/src/Plugin/Type/SelectionPluginManager.php index b4e17a1d5de55b82d516092074746ca5e78ebe40..786359399f7317b566ca232569ef170286bc29b9 100644 --- a/core/modules/entity_reference/src/Plugin/Type/SelectionPluginManager.php +++ b/core/modules/entity_reference/src/Plugin/Type/SelectionPluginManager.php @@ -7,15 +7,14 @@ namespace Drupal\entity_reference\Plugin\Type; -use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Component\Plugin\Factory\ReflectionFactory; +use Drupal\Component\Plugin\FallbackPluginManagerInterface; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\DefaultPluginManager; use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; -use Drupal\entity_reference\Plugin\Type\Selection\SelectionBroken; /** * Plugin type manager for Entity Reference Selection plugins. @@ -26,7 +25,7 @@ * @see \Drupal\entity_reference\Plugin\Derivative\SelectionBase * @see plugin_api */ -class SelectionPluginManager extends DefaultPluginManager { +class SelectionPluginManager extends DefaultPluginManager implements FallbackPluginManagerInterface { /** * {@inheritdoc} @@ -43,19 +42,6 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac $this->setCacheBackend($cache_backend, 'entity_reference_selection_plugins'); } - /** - * Overrides \Drupal\Component\Plugin\PluginManagerBase::createInstance(). - */ - public function createInstance($plugin_id, array $configuration = array()) { - // We want to provide a broken handler class whenever a class is not found. - try { - return parent::createInstance($plugin_id, $configuration); - } - catch (PluginException $e) { - return new SelectionBroken($configuration['field_definition']); - } - } - /** * Overrides \Drupal\Component\Plugin\PluginManagerBase::getInstance(). */ @@ -86,8 +72,12 @@ public function getInstance(array $options) { */ public function getSelectionGroups($entity_type) { $plugins = array(); + $definitions = $this->getDefinitions(); - foreach ($this->getDefinitions() as $plugin_id => $plugin) { + // Do not display the 'broken' plugin in the UI. + unset($definitions['broken']); + + foreach ($definitions as $plugin_id => $plugin) { if (empty($plugin['entity_types']) || in_array($entity_type, $plugin['entity_types'])) { $plugins[$plugin['group']][$plugin_id] = $plugin; } @@ -115,4 +105,11 @@ public function getSelectionHandler(FieldDefinitionInterface $field_definition, return $this->getInstance($options); } + /** + * {@inheritdoc} + */ + public function getFallbackPluginId($plugin_id, array $configuration = array()) { + return 'broken'; + } + } diff --git a/core/modules/entity_reference/src/Plugin/Type/Selection/SelectionBroken.php b/core/modules/entity_reference/src/Plugin/entity_reference/selection/Broken.php similarity index 87% rename from core/modules/entity_reference/src/Plugin/Type/Selection/SelectionBroken.php rename to core/modules/entity_reference/src/Plugin/entity_reference/selection/Broken.php index 37a526448d2cf056a7dcc69a0b76d814b06bc159..4ddde95f344fe733540b76438cb5069d00fb1335 100644 --- a/core/modules/entity_reference/src/Plugin/Type/Selection/SelectionBroken.php +++ b/core/modules/entity_reference/src/Plugin/entity_reference/selection/Broken.php @@ -12,7 +12,12 @@ use Drupal\Core\Form\FormStateInterface; /** - * A null implementation of SelectionInterface. + * Defines a fallback plugin for missing entity_reference selection plugins. + * + * @EntityReferenceSelection( + * id = "broken", + * label = @Translation("Broken/Missing") + * ) */ class SelectionBroken implements SelectionInterface {