By xano on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Description:
Plugins that are configurable should implement \Drupal\Component\Plugin\ConfigurablePluginInterface which lets other code not only get and set configuration on the plugin, but also allows the plugin to provide default configuration through a method. This replaces several custom default value implementations in the Block and Image modules.
namespace Drupal\foo;
use \Drupal\Component\Plugin\ConfigurablePluginInterface;
class Bar implements ConfigurablePluginInterface {
protected $configuration = array();
/**
* {@inheritdoc}
*/
public function getConfiguration() {
return $this->configuration + $this->defaultConfiguration();
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
$this->configuration = $configuration;
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return array(
'foo' => 'bar',
);
}
}
Impacts:
Module developers