diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Form/SettingsForm.php b/core/modules/aggregator/lib/Drupal/aggregator/Form/SettingsForm.php index 54dc385..1e9e906 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Form/SettingsForm.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Form/SettingsForm.php @@ -36,6 +36,13 @@ class SettingsForm extends SystemConfigFormBase { ); /** + * The instanciated plugin instances. + * + * @var array + */ + protected $instances = array(); + + /** * Constructs a \Drupal\aggregator\SettingsForm object. * * @param \Drupal\Core\Config\ConfigFactory $config_factory @@ -82,7 +89,7 @@ public function getFormID() { } /** - * Implements \Drupal\Core\Form\FormInterface::buildForm(). + * {@inheritdoc} */ public function buildForm(array $form, array &$form_state) { $config = $this->configFactory->get('aggregator.settings'); @@ -140,9 +147,10 @@ public function buildForm(array $form, array &$form_state) { foreach (array('fetcher', 'parser') as $type) { $active = $config->get($type); if (array_key_exists($active, $this->definitions[$type])) { - $form = $this->managers[$type] - ->createInstance($active) - ->settingsForm($form, $form_state); + $instance = $this->managers[$type]->createInstance($active); + $form = $instance->settingsForm($form, $form_state); + // Store the instance for validate and submit handlers. + $this->instances[] = $instance; } } @@ -151,33 +159,36 @@ public function buildForm(array $form, array &$form_state) { // Call settingsForm() for each active processor. foreach ($this->definitions['processor'] as $id => $definition) { if (in_array($id, $config->get('processors'))) { - $form = $this->managers['processor']->createInstance($id)->settingsForm($form, $form_state); + $instance = $this->managers['processor']->createInstance($id); + $form = $instance->settingsForm($form, $form_state); + // Store the instance for validate and submit handlers. + $this->instances[] = $instance; } } return parent::buildForm($form, $form_state); } /** - * Implements \Drupal\Core\Form\FormInterface::submitForm(). + * {@inheritdoc} + */ + public function validateForm(array &$form, array &$form_state) { + parent::validateForm($form, $form_state); + // Let active plugins validate their settings. + foreach ($this->instances as $instance) { + $instance->settingsValidate($form, $form_state); + } + } + + /** + * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { parent::submitForm($form, $form_state); $config = $this->configFactory->get('aggregator.settings'); - // Let active fetcher and parser save their settings. - foreach (array('fetcher', 'parser') as $type) { - $active = $config->get($type); - if (array_key_exists($active, $this->definitions[$type])) { - $this->managers[$type] - ->createInstance($active) - ->settingsSubmit($form, $form_state); - } - } - // Let active processors save their settings. - foreach ($this->definitions['processor'] as $id => $definition) { - if (in_array($id, $config->get('processors'))) { - $this->managers['processor']->createInstance($id)->settingsSubmit($form, $form_state); - } + // Let active plugins save their settings. + foreach ($this->instances as $instance) { + $instance->settingsSubmit($form, $form_state); } $config->set('items.allowed_html', $form_state['values']['aggregator_allowed_html_tags']);