diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/AggregatorPluginSettingsBase.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/AggregatorPluginSettingsBase.php index a89a641..55013e1 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/AggregatorPluginSettingsBase.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/AggregatorPluginSettingsBase.php @@ -7,13 +7,14 @@ namespace Drupal\aggregator\Plugin; +use Drupal\Component\Plugin\ConfigurablePluginInterface; use Drupal\Component\Plugin\PluginBase; use Drupal\Core\Plugin\PluginFormInterface; /** * Base class for aggregator plugins that implement settings forms. */ -abstract class AggregatorPluginSettingsBase extends PluginBase implements PluginFormInterface { +abstract class AggregatorPluginSettingsBase extends PluginBase implements PluginFormInterface, ConfigurablePluginInterface { /** * {@inheritdoc} diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/processor/DefaultProcessor.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/processor/DefaultProcessor.php index b44a448..3f27ecd 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/processor/DefaultProcessor.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/processor/DefaultProcessor.php @@ -50,8 +50,8 @@ class DefaultProcessor extends AggregatorPluginSettingsBase implements Processor * The configuration factory object. */ public function __construct(array $configuration, $plugin_id, array $plugin_definition, ConfigFactory $config) { - parent::__construct($configuration, $plugin_id, $plugin_definition); $this->configFactory = $config; + parent::__construct($configuration + $this->getConfiguration(), $plugin_id, $plugin_definition); } /** @@ -65,8 +65,7 @@ public static function create(ContainerInterface $container, array $configuratio * {@inheritdoc} */ public function buildConfigurationForm(array $form, array &$form_state) { - $config = $this->configFactory->get('aggregator.settings'); - $processors = $config->get('processors'); + $processors = $this->configuration['processors']; $info = $this->getPluginDefinition(); $items = drupal_map_assoc(array(3, 5, 10, 15, 20, 25), array($this, 'formatItems')); $period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval'); @@ -86,7 +85,7 @@ public function buildConfigurationForm(array $form, array &$form_state) { $form['processors'][$info['id']]['aggregator_summary_items'] = array( '#type' => 'select', '#title' => t('Number of items shown in listing pages'), - '#default_value' => $config->get('source.list_max'), + '#default_value' => $this->configuration['source']['list_max'], '#empty_value' => 0, '#options' => $items, ); @@ -94,7 +93,7 @@ public function buildConfigurationForm(array $form, array &$form_state) { $form['processors'][$info['id']]['aggregator_clear'] = array( '#type' => 'select', '#title' => t('Discard items older than'), - '#default_value' => $config->get('items.expire'), + '#default_value' => $this->configuration['items']['expire'], '#options' => $period, '#description' => t('Requires a correctly configured cron maintenance task.', array('@cron' => url('admin/reports/status'))), ); @@ -102,7 +101,7 @@ public function buildConfigurationForm(array $form, array &$form_state) { $form['processors'][$info['id']]['aggregator_category_selector'] = array( '#type' => 'radios', '#title' => t('Select categories using'), - '#default_value' => $config->get('source.category_selector'), + '#default_value' => $this->configuration['source']['category_selector'], '#options' => array('checkboxes' => t('checkboxes'), 'select' => t('multiple selector')), '#description' => t('For a small number of categories, checkboxes are easier to use, while a multiple selector works well with large numbers of categories.'), @@ -110,7 +109,7 @@ public function buildConfigurationForm(array $form, array &$form_state) { $form['processors'][$info['id']]['aggregator_teaser_length'] = array( '#type' => 'select', '#title' => t('Length of trimmed description'), - '#default_value' => $config->get('items.teaser_length'), + '#default_value' => $this->configuration['items']['teaser_length'], '#options' => drupal_map_assoc(array(0, 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000), array($this, 'formatCharacters')), '#description' => t('The maximum number of characters used in the trimmed version of content.'), ); @@ -121,12 +120,11 @@ public function buildConfigurationForm(array $form, array &$form_state) { * {@inheritdoc} */ public function submitConfigurationForm(array &$form, array &$form_state) { - $config = $this->configFactory->get('aggregator.settings'); - $config->set('items.expire', $form_state['values']['aggregator_clear']) - ->set('items.teaser_length', $form_state['values']['aggregator_teaser_length']) - ->set('source.list_max', $form_state['values']['aggregator_summary_items']) - ->set('source.category_selector', $form_state['values']['aggregator_category_selector']) - ->save(); + $this->configuration['items']['expire'] = $form_state['values']['aggregator_clear']; + $this->configuration['items']['teaser_length'] = $form_state['values']['aggregator_teaser_length']; + $this->configuration['source']['list_max'] = $form_state['values']['aggregator_summary_items']; + $this->configuration['source']['category_selector'] = $form_state['values']['aggregator_category_selector']; + $this->setConfiguration($this->configuration); } /** @@ -198,7 +196,7 @@ public function remove(Feed $feed) { * Expires items from a feed depending on expiration settings. */ public function postProcess(Feed $feed) { - $aggregator_clear = $this->configFactory->get('aggregator.settings')->get('items.expire'); + $aggregator_clear = $this->configuration['items']['expire']; if ($aggregator_clear != AGGREGATOR_CLEAR_NEVER) { // Remove all items that are older than flush item timer. @@ -215,6 +213,24 @@ public function postProcess(Feed $feed) { } /** + * {@inheritdoc} + */ + public function getConfiguration() { + return $this->configFactory->get('aggregator.settings')->get(); + } + + /** + * {@inheritdoc} + */ + public function setConfiguration(array $configuration) { + $config = $this->configFactory->get('aggregator.settings'); + foreach ($configuration as $key => $value) { + $config->set($key, $value); + } + $config->save(); + } + + /** * Helper function for drupal_map_assoc. * * @param int $count diff --git a/core/modules/aggregator/tests/modules/aggregator_test/lib/Drupal/aggregator_test/Plugin/aggregator/processor/TestProcessor.php b/core/modules/aggregator/tests/modules/aggregator_test/lib/Drupal/aggregator_test/Plugin/aggregator/processor/TestProcessor.php index afeda55..a0ba7f2 100644 --- a/core/modules/aggregator/tests/modules/aggregator_test/lib/Drupal/aggregator_test/Plugin/aggregator/processor/TestProcessor.php +++ b/core/modules/aggregator/tests/modules/aggregator_test/lib/Drupal/aggregator_test/Plugin/aggregator/processor/TestProcessor.php @@ -56,8 +56,8 @@ public static function create(ContainerInterface $container, array $configuratio * The configuration factory object. */ public function __construct(array $configuration, $plugin_id, array $plugin_definition, ConfigFactory $config) { - parent::__construct($configuration, $plugin_id, $plugin_definition); $this->configFactory = $config; + parent::__construct($configuration + $this->getConfiguration(), $plugin_id, $plugin_definition); } /** @@ -79,7 +79,7 @@ public function buildConfigurationForm(array $form, array &$form_state) { '#type' => 'number', '#min' => 1, '#max' => 1000, - '#default_value' => $this->configFactory->get('aggregator_test.settings')->get('items.dummy_length'), + '#default_value' => $this->configuration['items']['dummy_length'], ); return $form; } @@ -88,9 +88,8 @@ public function buildConfigurationForm(array $form, array &$form_state) { * {@inheritdoc} */ public function submitConfigurationForm(array &$form, array &$form_state) { - $this->configFactory->get('aggregator_test.settings') - ->set('items.dummy_length', $form_state['values']['dummy_length']) - ->save(); + $this->configuration['items']['dummy_length'] = $form_state['values']['dummy_length']; + $this->setConfiguration($this->configuration); } /** @@ -120,4 +119,22 @@ public function postProcess(Feed $feed) { $feed->save(); } + /** + * {@inheritdoc} + */ + public function getConfiguration() { + return $this->configFactory->get('aggregator_test.settings')->get(); + } + + /** + * {@inheritdoc} + */ + public function setConfiguration(array $configuration) { + $config = $this->configFactory->get('aggregator_test.settings'); + foreach ($configuration as $key => $value) { + $config->set($key, $value); + } + $config->save(); + } + }