Mercurial > hg > isophonics-drupal-site
diff core/lib/Drupal/Component/Plugin/PluginManagerBase.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 4c8ae668cc8c |
children |
line wrap: on
line diff
--- a/core/lib/Drupal/Component/Plugin/PluginManagerBase.php Tue Jul 10 15:07:59 2018 +0100 +++ b/core/lib/Drupal/Component/Plugin/PluginManagerBase.php Thu Feb 28 13:21:36 2019 +0000 @@ -29,7 +29,7 @@ /** * 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 @@ 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 { @@ -86,9 +85,28 @@ } /** + * 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); }