Mercurial > hg > isophonics-drupal-site
comparison 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 |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
27 protected $factory; | 27 protected $factory; |
28 | 28 |
29 /** | 29 /** |
30 * The object that returns the preconfigured plugin instance appropriate for a particular runtime condition. | 30 * The object that returns the preconfigured plugin instance appropriate for a particular runtime condition. |
31 * | 31 * |
32 * @var \Drupal\Component\Plugin\Mapper\MapperInterface | 32 * @var \Drupal\Component\Plugin\Mapper\MapperInterface|null |
33 */ | 33 */ |
34 protected $mapper; | 34 protected $mapper; |
35 | 35 |
36 /** | 36 /** |
37 * Gets the plugin discovery. | 37 * Gets the plugin discovery. |
74 if ($this instanceof FallbackPluginManagerInterface) { | 74 if ($this instanceof FallbackPluginManagerInterface) { |
75 try { | 75 try { |
76 return $this->getFactory()->createInstance($plugin_id, $configuration); | 76 return $this->getFactory()->createInstance($plugin_id, $configuration); |
77 } | 77 } |
78 catch (PluginNotFoundException $e) { | 78 catch (PluginNotFoundException $e) { |
79 $fallback_id = $this->getFallbackPluginId($plugin_id, $configuration); | 79 return $this->handlePluginNotFound($plugin_id, $configuration); |
80 return $this->getFactory()->createInstance($fallback_id, $configuration); | |
81 } | 80 } |
82 } | 81 } |
83 else { | 82 else { |
84 return $this->getFactory()->createInstance($plugin_id, $configuration); | 83 return $this->getFactory()->createInstance($plugin_id, $configuration); |
85 } | 84 } |
86 } | 85 } |
87 | 86 |
88 /** | 87 /** |
88 * Allows plugin managers to specify custom behavior if a plugin is not found. | |
89 * | |
90 * @param string $plugin_id | |
91 * The ID of the missing requested plugin. | |
92 * @param array $configuration | |
93 * An array of configuration relevant to the plugin instance. | |
94 * | |
95 * @return object | |
96 * A fallback plugin instance. | |
97 */ | |
98 protected function handlePluginNotFound($plugin_id, array $configuration) { | |
99 $fallback_id = $this->getFallbackPluginId($plugin_id, $configuration); | |
100 return $this->getFactory()->createInstance($fallback_id, $configuration); | |
101 } | |
102 | |
103 /** | |
89 * {@inheritdoc} | 104 * {@inheritdoc} |
90 */ | 105 */ |
91 public function getInstance(array $options) { | 106 public function getInstance(array $options) { |
107 if (!$this->mapper) { | |
108 throw new \BadMethodCallException(sprintf('%s does not support this method unless %s::$mapper is set.', static::class, static::class)); | |
109 } | |
92 return $this->mapper->getInstance($options); | 110 return $this->mapper->getInstance($options); |
93 } | 111 } |
94 | 112 |
95 } | 113 } |