Commit 248284df authored by Dries's avatar Dries

Issue #1889826 by tim.plunkett: DefaultFactory::getPluginClass() is very...

Issue #1889826 by tim.plunkett: DefaultFactory::getPluginClass() is very useful and should be public and static.
parent 4c19bdca
......@@ -41,7 +41,7 @@ public function __construct(DiscoveryInterface $discovery) {
* Implements Drupal\Component\Plugin\Factory\FactoryInterface::createInstance().
*/
public function createInstance($plugin_id, array $configuration) {
$plugin_class = $this->getPluginClass($plugin_id);
$plugin_class = static::getPluginClass($plugin_id, $this->discovery);
return new $plugin_class($configuration, $plugin_id, $this->discovery);
}
......@@ -50,12 +50,14 @@ public function createInstance($plugin_id, array $configuration) {
*
* @param array $plugin_id
* The id of a plugin.
* @param \Drupal\Component\Plugin\Discovery\DiscoveryInterface $discovery
* The discovery object.
*
* @return string
* The appropriate class name.
*/
protected function getPluginClass($plugin_id) {
$plugin_definition = $this->discovery->getDefinition($plugin_id);
public static function getPluginClass($plugin_id, DiscoveryInterface $discovery) {
$plugin_definition = $discovery->getDefinition($plugin_id);
if (empty($plugin_definition['class'])) {
throw new PluginException(sprintf('The plugin (%s) did not specify an instance class.', $plugin_id));
}
......
......@@ -20,7 +20,7 @@ class ReflectionFactory extends DefaultFactory {
* Implements Drupal\Component\Plugin\Factory\FactoryInterface::createInstance().
*/
public function createInstance($plugin_id, array $configuration) {
$plugin_class = $this->getPluginClass($plugin_id);
$plugin_class = static::getPluginClass($plugin_id, $this->discovery);
// Lets figure out of there's a constructor for this class and pull
// arguments from the $options array if so to populate it.
......
......@@ -18,7 +18,7 @@ class FormatterFactory extends DefaultFactory {
* Overrides Drupal\Component\Plugin\Factory\DefaultFactory::createInstance().
*/
public function createInstance($plugin_id, array $configuration) {
$plugin_class = $this->getPluginClass($plugin_id);
$plugin_class = static::getPluginClass($plugin_id, $this->discovery);
return new $plugin_class($plugin_id, $this->discovery, $configuration['instance'], $configuration['settings'], $configuration['label'], $configuration['view_mode']);
}
}
......@@ -18,7 +18,7 @@ class WidgetFactory extends DefaultFactory {
* Overrides Drupal\Component\Plugin\Factory\DefaultFactory::createInstance().
*/
public function createInstance($plugin_id, array $configuration) {
$plugin_class = $this->getPluginClass($plugin_id);
$plugin_class = static::getPluginClass($plugin_id, $this->discovery);
return new $plugin_class($plugin_id, $this->discovery, $configuration['instance'], $configuration['settings'], $configuration['weight']);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment