diff --git a/core/lib/Drupal/Core/Plugin/DefaultPluginBag.php b/core/lib/Drupal/Core/Plugin/DefaultPluginBag.php index 9fabf75..2d301f5 100644 --- a/core/lib/Drupal/Core/Plugin/DefaultPluginBag.php +++ b/core/lib/Drupal/Core/Plugin/DefaultPluginBag.php @@ -76,4 +76,64 @@ protected function initializePlugin($instance_id) { } } + /** + * Sorts all plugin instances in this bag. + * + * @return self + * Returns the plugin bag. + */ + public function sort() { + uasort($this->instanceIDs, array($this, 'sortHelper')); + return $this; + } + + /** + * Provides uasort() callback to sort plugins. + */ + public function sortHelper($aID, $bID) { + $a = $this->get($aID); + $b = $this->get($bID); + return strnatcasecmp($a->getPluginId(), $b->getPluginId()); + } + + /** + * Returns the current configuration of all plugins in this bag. + * + * @return array + * An associative array keyed by instance ID, whose values are up-to-date + * plugin configurations. + */ + public function getConfiguration() { + $instances = array(); + $this->rewind(); + foreach ($this as $instance_id => $instance) { + if ($instance instanceof ConfigurablePluginInterface) { + $instances[$instance_id] = $instance->getConfiguration(); + } + else { + $instances[$instance_id] = $this->configurations[$instance_id]; + } + } + return $instances; + } + + /** + * Updates the configuration for a plugin instance. + * + * If there is no plugin instance yet, a new will be instantiated. Otherwise, + * the existing instance is updated with the new configuration. + * + * @param string $instance_id + * The ID of a plugin to set the configuration for. + * @param array $configuration + * The plugin configuration to set. + */ + public function setConfiguration($instance_id, array $configuration) { + $this->configurations[$instance_id] = $configuration; + $instance = $this->get($instance_id); + if ($instance instanceof ConfigurablePluginInterface) { + $instance->setConfiguration($configuration); + } + } + } diff --git a/core/modules/block/lib/Drupal/block/BlockBase.php b/core/modules/block/lib/Drupal/block/BlockBase.php index cee4707..947439e 100644 --- a/core/modules/block/lib/Drupal/block/BlockBase.php +++ b/core/modules/block/lib/Drupal/block/BlockBase.php @@ -64,34 +64,14 @@ public function setConfiguration(array $configuration) { } /** - * Sets a particular value in the block settings. - * - * @param string $key - * The key of PluginBase::$configuration to set. - * @param mixed $value - * The value to set for the provided key. - * - * @todo This doesn't belong here. Move this into a new base class in - * http://drupal.org/node/1764380. - * @todo This does not set a value in config(), so the name is confusing. - * - * @see \Drupal\Component\Plugin\PluginBase::$configuration + * {@inheritdoc} */ public function setConfig($key, $value) { $this->configuration[$key] = $value; } /** - * Indicates whether block-specific criteria allow access to the block. - * - * Blocks with access restrictions that should always be applied, - * regardless of user-configured settings, should implement this method - * with that access control logic. - * - * @return bool - * FALSE to deny access to the block, or TRUE to allow access. - * - * @see hook_block_access() + * {@inheritdoc} */ public function access() { // By default, the block is visible unless user-configured rules indicate @@ -136,20 +116,7 @@ public function buildConfigurationForm(array $form, array &$form_state) { } /** - * Returns the configuration form elements specific to this block plugin. - * - * Blocks that need to add form elements to the normal block configuration - * form should implement this method. - * - * @param array $form - * The form definition array for the block configuration form. - * @param array $form_state - * An array containing the current state of the configuration form. - * - * @return array $form - * The renderable form array representing the entire configuration form. - * - * @see \Drupal\block\BlockBase::buildConfigurationForm() + * {@inheritdoc} */ public function blockForm($form, &$form_state) { return array(); @@ -170,20 +137,7 @@ public function validateConfigurationForm(array &$form, array &$form_state) { } /** - * Adds block type-specific validation for the block form. - * - * Note that this method takes the form structure and form state arrays for - * the full block configuration form as arguments, not just the elements - * defined in BlockBase::blockForm(). - * - * @param array $form - * The form definition array for the full block configuration form. - * @param array $form_state - * An array containing the current state of the configuration form. - * - * @see \Drupal\block\BlockBase::blockForm() - * @see \Drupal\block\BlockBase::blockSubmit() - * @see \Drupal\block\BlockBase::validateConfigurationForm() + * {@inheritdoc} */ public function blockValidate($form, &$form_state) {} @@ -207,20 +161,8 @@ public function submitConfigurationForm(array &$form, array &$form_state) { } /** - * Adds block type-specific submission handling for the block form. - * - * Note that this method takes the form structure and form state arrays for - * the full block configuration form as arguments, not just the elements - * defined in BlockBase::blockForm(). - * - * @param array $form - * The form definition array for the full block configuration form. - * @param array $form_state - * An array containing the current state of the configuration form. - * - * @see \Drupal\block\BlockBase::blockForm() - * @see \Drupal\block\BlockBase::blockValidate() - * @see \Drupal\block\BlockBase::submitConfigurationForm() + * {@inheritdoc} */ public function blockSubmit($form, &$form_state) {} + } diff --git a/core/modules/block/lib/Drupal/block/BlockPluginInterface.php b/core/modules/block/lib/Drupal/block/BlockPluginInterface.php index b960090..a5c4f52 100644 --- a/core/modules/block/lib/Drupal/block/BlockPluginInterface.php +++ b/core/modules/block/lib/Drupal/block/BlockPluginInterface.php @@ -18,8 +18,6 @@ * architecture and the relationships between the various objects, including * brif references to the important components that are not coupled to the * interface. - * - * @see \Drupal\block\BlockBase */ interface BlockPluginInterface extends ConfigurablePluginInterface, PluginFormInterface, PluginInspectionInterface { @@ -58,4 +56,70 @@ public function access(); */ public function build(); + /** + * Sets a particular value in the block settings. + * + * @param string $key + * The key of PluginBase::$configuration to set. + * @param mixed $value + * The value to set for the provided key. + * + * @todo This doesn't belong here. Move this into a new base class in + * http://drupal.org/node/1764380. + * @todo This does not set a value in config(), so the name is confusing. + * + * @see \Drupal\Component\Plugin\PluginBase::$configuration + */ + public function setConfig($key, $value); + + /** + * Returns the configuration form elements specific to this block plugin. + * + * Blocks that need to add form elements to the normal block configuration + * form should implement this method. + * + * @param array $form + * The form definition array for the block configuration form. + * @param array $form_state + * An array containing the current state of the configuration form. + * + * @return array $form + * The renderable form array representing the entire configuration form. + */ + public function blockForm($form, &$form_state); + + /** + * Adds block type-specific validation for the block form. + * + * Note that this method takes the form structure and form state arrays for + * the full block configuration form as arguments, not just the elements + * defined in BlockPluginInterface::blockForm(). + * + * @param array $form + * The form definition array for the full block configuration form. + * @param array $form_state + * An array containing the current state of the configuration form. + * + * @see \Drupal\block\BlockPluginInterface::blockForm() + * @see \Drupal\block\BlockPluginInterface::blockSubmit() + */ + public function blockValidate($form, &$form_state); + + /** + * Adds block type-specific submission handling for the block form. + * + * Note that this method takes the form structure and form state arrays for + * the full block configuration form as arguments, not just the elements + * defined in BlockPluginInterface::blockForm(). + * + * @param array $form + * The form definition array for the full block configuration form. + * @param array $form_state + * An array containing the current state of the configuration form. + * + * @see \Drupal\block\BlockPluginInterface::blockForm() + * @see \Drupal\block\BlockPluginInterface::blockValidate() + */ + public function blockSubmit($form, &$form_state); + } diff --git a/core/modules/filter/lib/Drupal/filter/FilterBag.php b/core/modules/filter/lib/Drupal/filter/FilterBag.php index fcb8aa9..3e7cec6 100644 --- a/core/modules/filter/lib/Drupal/filter/FilterBag.php +++ b/core/modules/filter/lib/Drupal/filter/FilterBag.php @@ -56,22 +56,6 @@ public function getAll() { } /** - * Updates the configuration for a filter plugin instance. - * - * If there is no plugin instance yet, a new will be instantiated. Otherwise, - * the existing instance is updated with the new configuration. - * - * @param string $instance_id - * The ID of a filter plugin to set the configuration for. - * @param array $configuration - * The filter plugin configuration to set. - */ - public function setConfig($instance_id, array $configuration) { - $this->configurations[$instance_id] = $configuration; - $this->get($instance_id)->setConfiguration($configuration); - } - - /** * {@inheritdoc} */ protected function initializePlugin($instance_id) { @@ -104,20 +88,15 @@ protected function initializePlugin($instance_id) { } /** - * Sorts all filter plugin instances in this bag. - * - * @return \Drupal\filter\FilterBag + * {@inheritdoc} */ public function sort() { $this->getAll(); - uasort($this->instanceIDs, array($this, 'sortHelper')); - return $this; + return parent::sort(); } /** - * uasort() callback to sort filters by status, weight, module, and name. - * - * @see \Drupal\filter\FilterFormatStorageController::preSave() + * {@inheritdoc} */ public function sortHelper($aID, $bID) { $a = $this->get($aID); @@ -134,22 +113,4 @@ public function sortHelper($aID, $bID) { return strnatcasecmp($a->getPluginId(), $b->getPluginId()); } - /** - * Returns the current configuration of all filters in this bag. - * - * @return array - * An associative array keyed by filter plugin instance ID, whose values - * are filter configurations. - * - * @see \Drupal\filter\Plugin\Filter\FilterInterface::getConfiguration() - */ - public function getConfiguration() { - $filters = array(); - $this->rewind(); - foreach ($this as $instance_id => $instance) { - $filters[$instance_id] = $instance->getConfiguration(); - } - return $filters; - } - } diff --git a/core/modules/filter/lib/Drupal/filter/Plugin/Core/Entity/FilterFormat.php b/core/modules/filter/lib/Drupal/filter/Plugin/Core/Entity/FilterFormat.php index 87d7447..7541b53 100644 --- a/core/modules/filter/lib/Drupal/filter/Plugin/Core/Entity/FilterFormat.php +++ b/core/modules/filter/lib/Drupal/filter/Plugin/Core/Entity/FilterFormat.php @@ -155,7 +155,7 @@ public function filters($instance_id = NULL) { public function setFilterConfig($instance_id, array $configuration) { $this->filters[$instance_id] = $configuration; if (isset($this->filterBag)) { - $this->filterBag->setConfig($instance_id, $configuration); + $this->filterBag->setConfiguration($instance_id, $configuration); } return $this; } diff --git a/core/modules/image/lib/Drupal/image/ImageEffectBag.php b/core/modules/image/lib/Drupal/image/ImageEffectBag.php index 437d8bb..11f173b 100644 --- a/core/modules/image/lib/Drupal/image/ImageEffectBag.php +++ b/core/modules/image/lib/Drupal/image/ImageEffectBag.php @@ -22,22 +22,6 @@ class ImageEffectBag extends DefaultPluginBag { protected $pluginKey = 'id'; /** - * Returns the current configuration of all image effects in this bag. - * - * @return array - * An associative array keyed by image effect UUID, whose values are image - * effect configurations. - */ - public function getConfiguration() { - $instances = array(); - $this->rewind(); - foreach ($this as $instance_id => $instance) { - $instances[$instance_id] = $instance->getConfiguration(); - } - return $instances; - } - - /** * Removes an instance ID. * * @param string $instance_id @@ -58,24 +42,22 @@ public function removeInstanceID($instance_id) { * The image effect configuration to set. * * @return string + * The image effect UUID. */ - public function setConfig(array $configuration) { + public function updateConfiguration(array $configuration) { // Derive the instance ID from the configuration. if (empty($configuration['uuid'])) { $uuid_generator = new Uuid(); $configuration['uuid'] = $uuid_generator->generate(); } $instance_id = $configuration['uuid']; - $this->configurations[$instance_id] = $configuration; - $this->get($instance_id)->setConfiguration($configuration); + $this->setConfiguration($instance_id, $configuration); $this->addInstanceID($instance_id); return $instance_id; } /** - * Sorts all image effect instances in this bag. - * - * @return self + * {@inheritdoc} */ public function sort() { uasort($this->configurations, 'drupal_sort_weight'); diff --git a/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php b/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php index 8f9e5bd..2b1afbf 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php +++ b/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php @@ -352,7 +352,7 @@ public function getEffects() { * {@inheritdoc} */ public function saveImageEffect(array $configuration) { - $effect_id = $this->getEffects()->setConfig($configuration); + $effect_id = $this->getEffects()->updateConfiguration($configuration); $this->save(); return $effect_id; } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php index b0cbb7b..3957677 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php @@ -99,6 +99,21 @@ */ protected $usesAreas = TRUE; + /** + * Constructs a new DisplayPluginBase object. + * + * Because DisplayPluginBase::initDisplay() takes the display configuration by + * reference and handles it differently than usual plugin configuration, pass + * an empty array of configuration to the parent. This prevents our + * configuration from being duplicated. + * + * @todo Replace DisplayPluginBase::$display with + * DisplayPluginBase::$configuration to standardize with other plugins. + */ + public function __construct(array $configuration, $plugin_id, array $plugin_definition) { + parent::__construct(array(), $plugin_id, $plugin_definition); + } + public function initDisplay(ViewExecutable $view, array &$display, array &$options = NULL) { $this->setOptionDefaults($this->options, $this->defineOptions()); $this->view = $view;