diff --git a/core/lib/Drupal/Component/Plugin/FallbackPluginManagerInterface.php b/core/lib/Drupal/Component/Plugin/FallbackPluginManagerInterface.php index 73fde08..da41111 100644 --- a/core/lib/Drupal/Component/Plugin/FallbackPluginManagerInterface.php +++ b/core/lib/Drupal/Component/Plugin/FallbackPluginManagerInterface.php @@ -12,16 +12,16 @@ interface FallbackPluginManagerInterface { /** - * Returns a fallback instance of a missing plugin. + * Returns a fallback id for a missing plugin. * * @param string $plugin_id * The ID of the missing requested plugin. * @param array $configuration * An array of configuration relevant to the plugin instance. * - * @return object - * A fully configured fallback plugin instance. + * @return string + * The id of an existing plugin to use for ... why isn't this in the factory? */ - public function createFallbackInstance($plugin_id, array $configuration = array()); + public function getFallbackPluginId($plugin_id, array $configuration = array()); } diff --git a/core/lib/Drupal/Component/Plugin/PluginManagerBase.php b/core/lib/Drupal/Component/Plugin/PluginManagerBase.php index eb76e60..58c8ebf 100644 --- a/core/lib/Drupal/Component/Plugin/PluginManagerBase.php +++ b/core/lib/Drupal/Component/Plugin/PluginManagerBase.php @@ -64,7 +64,8 @@ public function createInstance($plugin_id, array $configuration = array()) { return $this->factory->createInstance($plugin_id, $configuration); } catch (PluginNotFoundException $e) { - return $this->createFallbackInstance($plugin_id, $configuration); + $fallback_id = $this->getFallbackPluginId($plugin_id, $configuration); + return $this->factory->createInstance($fallback_id, $configuration); } } else { diff --git a/core/modules/filter/src/FilterPluginManager.php b/core/modules/filter/src/FilterPluginManager.php index 40dcd98..fd10336 100644 --- a/core/modules/filter/src/FilterPluginManager.php +++ b/core/modules/filter/src/FilterPluginManager.php @@ -11,7 +11,6 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\DefaultPluginManager; -use Drupal\filter\Plugin\Filter\FilterNull; /** * Manages text processing filters. @@ -44,28 +43,8 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac /** * {@inheritdoc} */ - public function getDefinition($plugin_id, $exception_on_invalid = TRUE) { - $definitions = $this->getDefinitions(); - // Avoid using a ternary that would create a copy of the array. - if (isset($definitions[$plugin_id])) { - return $definitions[$plugin_id]; - } - // If the requested filter is missing, use the null filter. - return $definitions['filter_null']; + public function getFallbackPluginId($plugin_id, array $configuration = array()) { + return 'filter_null'; } - /** - * {@inheritdoc} - */ - public function createFallbackInstance($plugin_id, array $configuration = array()) { - $definition = array( - 'id' => "filter_null", - 'title' => t("Provides a fallback for missing filters. Do not use."), - 'type' => Drupal\filter\Plugin\FilterInterface::TYPE_HTML_RESTRICTOR, - 'weight' => -10 - ); - return new FilterNull($configuration, $plugin_id, $definition); - } - - } diff --git a/core/modules/filter/src/Plugin/Filter/FilterNull.php b/core/modules/filter/src/Plugin/Filter/FilterNull.php index 4e2bb53..3b2d943 100644 --- a/core/modules/filter/src/Plugin/Filter/FilterNull.php +++ b/core/modules/filter/src/Plugin/Filter/FilterNull.php @@ -16,6 +16,13 @@ * The filter system uses this filter to replace missing filters (for example, * if a filter module has been disabled) that are still part of defined text * formats. It returns an empty string. + * + * @Filter( + * id = "filter_null", + * title = @Translation("Provides a fallback for missing filters. Do not use."), + * type = Drupal\filter\Plugin\FilterInterface::TYPE_HTML_RESTRICTOR, + * weight = -10 + * ) */ class FilterNull extends FilterBase { diff --git a/core/modules/views/src/Plugin/ViewsHandlerManager.php b/core/modules/views/src/Plugin/ViewsHandlerManager.php index d817f62..0aac439 100644 --- a/core/modules/views/src/Plugin/ViewsHandlerManager.php +++ b/core/modules/views/src/Plugin/ViewsHandlerManager.php @@ -37,20 +37,6 @@ class ViewsHandlerManager extends DefaultPluginManager implements FallbackPlugin protected $handlerType; /** - * The list of fallback classes for all handler types. - * - * @var array - */ - protected $fallbackClassNames = array( - 'area' => 'Drupal\views\Plugin\views\area\Broken', - 'argument' => 'Drupal\views\Plugin\views\argument\Broken', - 'field' => 'Drupal\views\Plugin\views\field\Broken', - 'filter' => 'Drupal\views\Plugin\views\filter\Broken', - 'relationship' => 'Drupal\views\Plugin\views\relationship\Broken', - 'sort' => 'Drupal\views\Plugin\views\sort\Broken', - ); - - /** * Constructs a ViewsHandlerManager object. * * @param string $handler_type @@ -117,32 +103,21 @@ public function getHandler($item, $override = NULL) { $plugin_id = $override ? : $definition['id']; // Try to use the overridden handler. $handler = $this->createInstance($plugin_id, $definition); - if (method_exists($handler, 'broken') && $handler->broken()) { + if ($override && method_exists($handler, 'broken') && $handler->broken()) { $handler = $this->createInstance($definition['id'], $definition); } return $handler; } - return $this->createFallbackInstance('broken', $item); - } - /** - * Gets the fallback class for the current handler type. - * - * @return string - */ - protected function getFallbackPluginClassName() { - return $this->fallbackClassNames[$this->handlerType]; + // Finally, use the 'broken' handler. + return $this->createInstance('broken', array('original_configuration' => $item)); } /** * {@inheritdoc} */ - public function createFallbackInstance($plugin_id, array $configuration = array()) { - $plugin_class = $this->getFallbackPluginClassName(); - $plugin_definition = array('id' => 'broken'); - - // Otherwise, create the plugin directly. - $instance = new $plugin_class(array('original_configuration' => $configuration), $plugin_id, $plugin_definition); + public function createInstance($plugin_id, array $configuration = array()) { + $instance = parent::createInstance($plugin_id, $configuration); if ($instance instanceof HandlerBase) { $instance->setModuleHandler($this->moduleHandler); $instance->setViewsData($this->viewsData); @@ -150,17 +125,10 @@ public function createFallbackInstance($plugin_id, array $configuration = array( return $instance; } - /** * {@inheritdoc} */ - public function createInstance($plugin_id, array $configuration = array()) { - $instance = parent::createInstance($plugin_id, $configuration); - if ($instance instanceof HandlerBase) { - $instance->setModuleHandler($this->moduleHandler); - $instance->setViewsData($this->viewsData); - } - return $instance; + public function getFallbackPluginId($plugin_id, array $configuration = array()) { + return 'broken'; } - } diff --git a/core/modules/views/src/Plugin/views/area/Broken.php b/core/modules/views/src/Plugin/views/area/Broken.php index 3053614..677cb8e 100644 --- a/core/modules/views/src/Plugin/views/area/Broken.php +++ b/core/modules/views/src/Plugin/views/area/Broken.php @@ -13,6 +13,8 @@ * A special handler to take the place of missing or broken handlers. * * @ingroup views_area_handlers + * + * @ViewsArea("broken") */ class Broken extends AreaPluginBase { use BrokenHandlerTrait; diff --git a/core/modules/views/src/Plugin/views/argument/Broken.php b/core/modules/views/src/Plugin/views/argument/Broken.php index 92de01f..1313185 100644 --- a/core/modules/views/src/Plugin/views/argument/Broken.php +++ b/core/modules/views/src/Plugin/views/argument/Broken.php @@ -13,6 +13,8 @@ * A special handler to take the place of missing or broken handlers. * * @ingroup views_argument_handlers + * + * @ViewsArgument("broken") */ class Broken extends ArgumentPluginBase { use BrokenHandlerTrait; diff --git a/core/modules/views/src/Plugin/views/field/Broken.php b/core/modules/views/src/Plugin/views/field/Broken.php index 758165e..dea772e 100644 --- a/core/modules/views/src/Plugin/views/field/Broken.php +++ b/core/modules/views/src/Plugin/views/field/Broken.php @@ -13,6 +13,8 @@ * A special handler to take the place of missing or broken handlers. * * @ingroup views_field_handlers + * + * @ViewsField("broken") */ class Broken extends FieldPluginBase { use BrokenHandlerTrait; diff --git a/core/modules/views/src/Plugin/views/filter/Broken.php b/core/modules/views/src/Plugin/views/filter/Broken.php index bbef126..be2e696 100644 --- a/core/modules/views/src/Plugin/views/filter/Broken.php +++ b/core/modules/views/src/Plugin/views/filter/Broken.php @@ -15,6 +15,8 @@ * A special handler to take the place of missing or broken handlers. * * @ingroup views_filter_handlers + * + * @ViewsFilter("broken") */ class Broken extends FilterPluginBase { use BrokenHandlerTrait; diff --git a/core/modules/views/src/Plugin/views/relationship/Broken.php b/core/modules/views/src/Plugin/views/relationship/Broken.php index c09cc15..f074832 100644 --- a/core/modules/views/src/Plugin/views/relationship/Broken.php +++ b/core/modules/views/src/Plugin/views/relationship/Broken.php @@ -13,6 +13,8 @@ * A special handler to take the place of missing or broken handlers. * * @ingroup views_relationship_handlers + * + * @ViewsRelationship("broken") */ class Broken extends RelationshipPluginBase { use BrokenHandlerTrait; diff --git a/core/modules/views/src/Plugin/views/sort/Broken.php b/core/modules/views/src/Plugin/views/sort/Broken.php index 0b6d5f7..509f327 100644 --- a/core/modules/views/src/Plugin/views/sort/Broken.php +++ b/core/modules/views/src/Plugin/views/sort/Broken.php @@ -13,6 +13,8 @@ * A special handler to take the place of missing or broken handlers. * * @ingroup views_sort_handlers + * + * @ViewsSort("broken") */ class Broken extends SortPluginBase { use BrokenHandlerTrait;