Commit bedfc1a7 authored by alexpott's avatar alexpott

Issue #2368443 by amateescu: Use the new FallbackPluginManagerInterface in...

Issue #2368443 by amateescu: Use the new FallbackPluginManagerInterface in ER's selection plugin manager.
parent de1d788c
......@@ -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';
}
}
......@@ -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 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment