diff --git a/core/lib/Drupal/Component/Plugin/FallbackPluginManagerInterface.php b/core/lib/Drupal/Component/Plugin/FallbackPluginManagerInterface.php new file mode 100644 index 0000000..73fde08 --- /dev/null +++ b/core/lib/Drupal/Component/Plugin/FallbackPluginManagerInterface.php @@ -0,0 +1,27 @@ +factory->createInstance($plugin_id, $configuration); + // If this PluginManager has fallback capabilities catch + // PluginNotFoundExceptions. + if ($this instanceof FallbackPluginManagerInterface) { + try { + return $this->factory->createInstance($plugin_id, $configuration); + } + catch (PluginNotFoundException $e) { + return $this->createFallbackInstance($plugin_id, $configuration); + } + } + else { + return $this->factory->createInstance($plugin_id, $configuration); + } } /** diff --git a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php index e1d0731..9cf2b94 100644 --- a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php +++ b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php @@ -9,7 +9,6 @@ use Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface; use Drupal\Component\Plugin\Discovery\DiscoveryCachedTrait; -use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator; use Drupal\Component\Plugin\PluginManagerBase; use Drupal\Component\Plugin\PluginManagerInterface; @@ -17,7 +16,6 @@ use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; use Drupal\Core\Plugin\Factory\ContainerFactory; diff --git a/core/modules/filter/src/FilterPluginManager.php b/core/modules/filter/src/FilterPluginManager.php index 77a3c71..40dcd98 100644 --- a/core/modules/filter/src/FilterPluginManager.php +++ b/core/modules/filter/src/FilterPluginManager.php @@ -7,9 +7,11 @@ namespace Drupal\filter; +use Drupal\Component\Plugin\FallbackPluginManagerInterface; 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. @@ -20,7 +22,7 @@ * @see \Drupal\filter\Plugin\FilterBase * @see plugin_api */ -class FilterPluginManager extends DefaultPluginManager { +class FilterPluginManager extends DefaultPluginManager implements FallbackPluginManagerInterface { /** * Constructs a FilterPluginManager object. @@ -52,4 +54,18 @@ public function getDefinition($plugin_id, $exception_on_invalid = TRUE) { return $definitions['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 3b2d943..4e2bb53 100644 --- a/core/modules/filter/src/Plugin/Filter/FilterNull.php +++ b/core/modules/filter/src/Plugin/Filter/FilterNull.php @@ -16,13 +16,6 @@ * 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 7b7b76e..9a2b5ec 100644 --- a/core/modules/views/src/Plugin/ViewsHandlerManager.php +++ b/core/modules/views/src/Plugin/ViewsHandlerManager.php @@ -7,17 +7,18 @@ namespace Drupal\views\Plugin; -use Drupal\Component\Plugin\Exception\PluginException; +use Drupal\Component\Plugin\FallbackPluginManagerInterface; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\DefaultPluginManager; use Drupal\views\ViewsData; use Symfony\Component\DependencyInjection\Container; +use Drupal\views\Plugin\views\HandlerBase; /** * Plugin type manager for all views handlers. */ -class ViewsHandlerManager extends DefaultPluginManager { +class ViewsHandlerManager extends DefaultPluginManager implements FallbackPluginManagerInterface { /** * The views data cache. @@ -36,6 +37,20 @@ class ViewsHandlerManager extends DefaultPluginManager { 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 @@ -101,27 +116,42 @@ public function getHandler($item, $override = NULL) { // @todo This is crazy. Find a way to remove the override functionality. $plugin_id = $override ? : $definition['id']; // Try to use the overridden handler. - try { - return $this->createInstance($plugin_id, $definition); - } - catch (PluginException $e) { - // If that fails, use the original handler. - try { - return $this->createInstance($definition['id'], $definition); - } - catch (PluginException $e) { - // Deliberately empty, this case is handled generically below. - } + $handler = $this->createInstance($plugin_id, $definition); + if ($handler->broken()) { + $handler = $this->createInstance($definition['id'], $definition); } + return $handler; } + return $this->createFallbackInstance('broken', $item); + } - // Finally, use the 'broken' handler. - return $this->createInstance('broken', array('original_configuration' => $item)); + /** + * Gets the fallback class for the current handler type. + * + * @return string + */ + protected function getFallbackPluginClassName() { + return $this->fallbackClassNames[$this->handlerType]; } /** * {@inheritdoc} */ + public function createFallbackInstance($plugin_id, array $configuration = array()) { + $plugin_class = $this->getFallbackPluginClassName(); + $plugin_definition = array('id' => 'broken'); + if (is_subclass_of($plugin_class, 'Drupal\Core\Plugin\ContainerFactoryPluginInterface')) { + return $plugin_class::create(\Drupal::getContainer(), $configuration, $plugin_id, $plugin_definition); + } + + // Otherwise, create the plugin directly. + return new $plugin_class(array('original_configuration' => $configuration), $plugin_id, $plugin_definition); + } + + + /** + * {@inheritdoc} + */ public function createInstance($plugin_id, array $configuration = array()) { $instance = parent::createInstance($plugin_id, $configuration); if ($instance instanceof HandlerBase) { diff --git a/core/modules/views/src/Plugin/views/area/Broken.php b/core/modules/views/src/Plugin/views/area/Broken.php index 677cb8e..3053614 100644 --- a/core/modules/views/src/Plugin/views/area/Broken.php +++ b/core/modules/views/src/Plugin/views/area/Broken.php @@ -13,8 +13,6 @@ * 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 1313185..92de01f 100644 --- a/core/modules/views/src/Plugin/views/argument/Broken.php +++ b/core/modules/views/src/Plugin/views/argument/Broken.php @@ -13,8 +13,6 @@ * 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 dea772e..758165e 100644 --- a/core/modules/views/src/Plugin/views/field/Broken.php +++ b/core/modules/views/src/Plugin/views/field/Broken.php @@ -13,8 +13,6 @@ * 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 be2e696..bbef126 100644 --- a/core/modules/views/src/Plugin/views/filter/Broken.php +++ b/core/modules/views/src/Plugin/views/filter/Broken.php @@ -15,8 +15,6 @@ * 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 f074832..c09cc15 100644 --- a/core/modules/views/src/Plugin/views/relationship/Broken.php +++ b/core/modules/views/src/Plugin/views/relationship/Broken.php @@ -13,8 +13,6 @@ * 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 509f327..0b6d5f7 100644 --- a/core/modules/views/src/Plugin/views/sort/Broken.php +++ b/core/modules/views/src/Plugin/views/sort/Broken.php @@ -13,8 +13,6 @@ * A special handler to take the place of missing or broken handlers. * * @ingroup views_sort_handlers - * - * @ViewsSort("broken") */ class Broken extends SortPluginBase { use BrokenHandlerTrait;