X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Flib%2FDrupal%2FComponent%2FPlugin%2FPluginManagerBase.php;fp=web%2Fcore%2Flib%2FDrupal%2FComponent%2FPlugin%2FPluginManagerBase.php;h=d7342da2ed18c69bb05fe2b124aca55e88d616bd;hp=34416ff4371d84974984205b07b2cca8ffba0c69;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/lib/Drupal/Component/Plugin/PluginManagerBase.php b/web/core/lib/Drupal/Component/Plugin/PluginManagerBase.php index 34416ff43..d7342da2e 100644 --- a/web/core/lib/Drupal/Component/Plugin/PluginManagerBase.php +++ b/web/core/lib/Drupal/Component/Plugin/PluginManagerBase.php @@ -29,7 +29,7 @@ abstract class PluginManagerBase implements PluginManagerInterface { /** * The object that returns the preconfigured plugin instance appropriate for a particular runtime condition. * - * @var \Drupal\Component\Plugin\Mapper\MapperInterface + * @var \Drupal\Component\Plugin\Mapper\MapperInterface|null */ protected $mapper; @@ -76,8 +76,7 @@ abstract class PluginManagerBase implements PluginManagerInterface { return $this->getFactory()->createInstance($plugin_id, $configuration); } catch (PluginNotFoundException $e) { - $fallback_id = $this->getFallbackPluginId($plugin_id, $configuration); - return $this->getFactory()->createInstance($fallback_id, $configuration); + return $this->handlePluginNotFound($plugin_id, $configuration); } } else { @@ -85,10 +84,29 @@ abstract class PluginManagerBase implements PluginManagerInterface { } } + /** + * Allows plugin managers to specify custom behavior if a plugin is not found. + * + * @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 fallback plugin instance. + */ + protected function handlePluginNotFound($plugin_id, array $configuration) { + $fallback_id = $this->getFallbackPluginId($plugin_id, $configuration); + return $this->getFactory()->createInstance($fallback_id, $configuration); + } + /** * {@inheritdoc} */ public function getInstance(array $options) { + if (!$this->mapper) { + throw new \BadMethodCallException(sprintf('%s does not support this method unless %s::$mapper is set.', static::class, static::class)); + } return $this->mapper->getInstance($options); }