diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index f52a3b7..d1f5de9 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -628,4 +628,20 @@ public static function accessManager() { return static::$container->get('access_manager'); } + /** + * Returns a class instance with a given class definition. + * + * @param string $definition + * A class name or service name. + * + * @throws \InvalidArgumentException + * If $class is not a valid service identifier and the class does not exist. + * + * @return object + * The instance of the class. + */ + public static function resolve($definition) { + return static::$container->get('class_resolver')->getInstanceFromDefinition($definition); + } + } diff --git a/core/lib/Drupal/Core/Form/ConfigFormBaseTrait.php b/core/lib/Drupal/Core/Form/ConfigFormBaseTrait.php index 7164118..4d8a2f7 100644 --- a/core/lib/Drupal/Core/Form/ConfigFormBaseTrait.php +++ b/core/lib/Drupal/Core/Form/ConfigFormBaseTrait.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\Core\Form\ConfigFormBase. + * Contains \Drupal\Core\Form\ConfigFormBaseTrait. */ namespace Drupal\Core\Form; @@ -14,11 +14,10 @@ /** * Retrieves a configuration object. * - * Overrides \Drupal\Core\Form\FormBase::config() so that configuration is - * returned override free. This ensures that overrides do not pollute saved - * configuration. - * - * @fixme improve document about why this is public for form alters + * Objects that use the trait need to implement the + * \Drupal\Core\Form\ConfigFormBaseTrait::getEditableConfigNames() to declare + * which configuration objects this method returns override free and mutable. + * This ensures that overrides do not pollute saved configuration. * * @param string $name * The name of the configuration object to retrieve. The name corresponds to @@ -26,10 +25,10 @@ * the config object returned will contain the contents of book.admin * configuration file. * - * @return \Drupal\Core\Config\Config + * @return \Drupal\Core\Config\Config|\Drupal\Core\Config\ImmutableConfig * A configuration object. */ - public function config($name) { + protected function config($name) { /** @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory */ if (method_exists($this, 'configFactory')) { $config_factory = $this->configFactory(); @@ -41,9 +40,22 @@ public function config($name) { // @todo throw a better exception throw new \RuntimeException('No config factory available for ConfigFormBaseTrait'); } - // Get a mutable object from the factory. - $config = $config_factory->getEditable($name); + if (in_array($name, $this->getEditableConfigNames())) { + // Get a mutable object from the factory. + $config = $config_factory->getEditable($name); + } + else { + $config = $config_factory->get($name); + } return $config; } + /** + * Gets the configuration names that will be editable. + * + * @return array + * An array of configuration object names that the config + */ + abstract protected function getEditableConfigNames(); + } diff --git a/core/lib/Drupal/Core/Form/FormAlterInterface.php b/core/lib/Drupal/Core/Form/FormAlterInterface.php new file mode 100644 index 0000000..29e5102 --- /dev/null +++ b/core/lib/Drupal/Core/Form/FormAlterInterface.php @@ -0,0 +1,18 @@ +loadInclude($module, $type, $name); } - /** - * @todo - * @param $name - * @return mixed - */ - public function config($name) { - $form_object = $this->getFormObject(); - if (method_exists($form_object, 'config')) { - return $form_object->config($name); - } - return \Drupal::config($name); - } - - } diff --git a/core/lib/Drupal/Core/Form/FormStateInterface.php b/core/lib/Drupal/Core/Form/FormStateInterface.php index 535385d..8b6a02a 100644 --- a/core/lib/Drupal/Core/Form/FormStateInterface.php +++ b/core/lib/Drupal/Core/Form/FormStateInterface.php @@ -1046,11 +1046,4 @@ public function isValidationComplete(); */ public function cleanValues(); - /** - * @todo - * @param $name - * @return mixed - */ - public function config($name); - } diff --git a/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php b/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php index ba55764..0354e25 100644 --- a/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php +++ b/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php @@ -100,6 +100,17 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return [ + 'system.date', + 'system.site', + 'update.settings', + ]; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $form['#title'] = $this->t('Configure site'); diff --git a/core/modules/aggregator/src/Form/SettingsForm.php b/core/modules/aggregator/src/Form/SettingsForm.php index ff6fd62..69c5ed6 100644 --- a/core/modules/aggregator/src/Form/SettingsForm.php +++ b/core/modules/aggregator/src/Form/SettingsForm.php @@ -99,6 +99,13 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['aggregator.settings']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('aggregator.settings'); diff --git a/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php b/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php index 99f589d..8290527 100644 --- a/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php +++ b/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php @@ -110,6 +110,13 @@ public static function create(ContainerInterface $container, array $configuratio /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['aggregator.settings']; + } + + /** + * {@inheritdoc} + */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $config = $this->config('aggregator.settings'); $processors = $config->get('processors'); diff --git a/core/modules/aggregator/tests/modules/aggregator_test/src/Plugin/aggregator/processor/TestProcessor.php b/core/modules/aggregator/tests/modules/aggregator_test/src/Plugin/aggregator/processor/TestProcessor.php index 6248d0a..6e08844 100644 --- a/core/modules/aggregator/tests/modules/aggregator_test/src/Plugin/aggregator/processor/TestProcessor.php +++ b/core/modules/aggregator/tests/modules/aggregator_test/src/Plugin/aggregator/processor/TestProcessor.php @@ -60,6 +60,13 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['aggregator_test.settings']; + } + + /** + * {@inheritdoc} + */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $processors = $this->config('aggregator.settings')->get('processors'); $info = $this->getPluginDefinition(); diff --git a/core/modules/book/src/Form/BookSettingsForm.php b/core/modules/book/src/Form/BookSettingsForm.php index fe1db37..0db0dc5 100644 --- a/core/modules/book/src/Form/BookSettingsForm.php +++ b/core/modules/book/src/Form/BookSettingsForm.php @@ -25,6 +25,13 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['book.settings']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $types = node_type_get_names(); $config = $this->config('book.settings'); diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module index 791dd0c..5f85085 100644 --- a/core/modules/contact/contact.module +++ b/core/modules/contact/contact.module @@ -147,33 +147,10 @@ function contact_mail($key, &$message, $params) { * @see \Drupal\user\ProfileForm::form() */ function contact_form_user_form_alter(&$form, FormStateInterface $form_state) { - $form['contact'] = array( - '#type' => 'details', - '#title' => t('Contact settings'), - '#open' => TRUE, - '#weight' => 5, - ); - $account = $form_state->getFormObject()->getEntity(); - if (!\Drupal::currentUser()->isAnonymous() && $account->id()) { - $account_data = \Drupal::service('user.data')->get('contact', $account->id(), 'enabled'); - } - $form['contact']['contact'] = array( - '#type' => 'checkbox', - '#title' => t('Personal contact form'), - '#default_value' => isset($account_data) ? $account_data : \Drupal::config('contact.settings')->get('user_default_enabled'), - '#description' => t('Allow other users to contact you via a personal contact form which keeps your email address hidden. Note that some privileged users such as site administrators are still able to contact you even if you choose to disable this feature.'), - ); - $form['actions']['submit']['#submit'][] = 'contact_user_profile_form_submit'; -} - -/** - * Submit callback for the user profile form to save the contact page setting. - */ -function contact_user_profile_form_submit($form, FormStateInterface $form_state) { - $account = $form_state->getFormObject()->getEntity(); - if ($account->id() && $form_state->hasValue('contact')) { - \Drupal::service('user.data')->set('contact', $account->id(), 'enabled', (int) $form_state->getValue('contact')); - } + /** @var \Drupal\contact\Form\UserFormAlter $alter */ + $alter = \Drupal::resolve('Drupal\contact\Form\UserFormAlter'); + $alter->alter($form, $form_state); + $form['actions']['submit']['#submit'][] = array($alter, 'submit'); } /** @@ -184,30 +161,9 @@ function contact_user_profile_form_submit($form, FormStateInterface $form_state) * @see \Drupal\user\AccountSettingsForm */ function contact_form_user_admin_settings_alter(&$form, FormStateInterface $form_state) { - $form['contact'] = array( - '#type' => 'details', - '#title' => t('Contact settings'), - '#open' => TRUE, - '#weight' => 0, - ); - $form['contact']['contact_default_status'] = array( - '#type' => 'checkbox', - '#title' => t('Enable the personal contact form by default for new users'), - '#description' => t('Changing this setting will not affect existing users.'), - // @see \Drupal\Core\Form\ConfigFormBase::config() - '#default_value' => $form_state->config('contact.settings')->get('user_default_enabled'), - ); + /** @var \Drupal\contact\Form\UserAccountSettingsFormAlter $alter */ + $alter = \Drupal::resolve('Drupal\contact\Form\UserAccountSettingsFormAlter'); + $alter->alter($form, $form_state); // Add submit handler to save contact configuration. - $form['#submit'][] = 'contact_form_user_admin_settings_submit'; -} - -/** - * Form submission handler for user_admin_settings(). - * - * @see contact_form_user_admin_settings_alter() - */ -function contact_form_user_admin_settings_submit($form, FormStateInterface $form_state) { - $form_state->config('contact.settings') - ->set('user_default_enabled', $form_state->getValue('contact_default_status')) - ->save(); + $form['#submit'][] = array($alter, 'submit'); } diff --git a/core/modules/contact/src/ContactFormEditForm.php b/core/modules/contact/src/ContactFormEditForm.php index 1744f1b..520f5b0 100644 --- a/core/modules/contact/src/ContactFormEditForm.php +++ b/core/modules/contact/src/ContactFormEditForm.php @@ -38,6 +38,12 @@ public static function create(ContainerInterface $container) { ); } + /** + * {@inheritdoc} + */ + protected function getEditableConfigNames() { + return ['contact.settings']; + } /** * {@inheritdoc} @@ -46,7 +52,7 @@ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); $contact_form = $this->entity; - $default_form = $this->config('contact.settings')->getOriginal('default_form', FALSE); + $default_form = $this->config('contact.settings')->get('default_form'); $form['label'] = array( '#type' => 'textfield', diff --git a/core/modules/contact/src/Form/UserAccountSettingsFormAlter.php b/core/modules/contact/src/Form/UserAccountSettingsFormAlter.php new file mode 100644 index 0000000..8eb9d3b --- /dev/null +++ b/core/modules/contact/src/Form/UserAccountSettingsFormAlter.php @@ -0,0 +1,86 @@ +configFactory = $config_factory; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('config.factory') + ); + } + + /** + * {@inheritdoc} + */ + protected function getEditableConfigNames() { + return ['contact.settings']; + } + + /** + * {@inheritdoc} + */ + public function alter(array &$form, FormStateInterface $form_state) { + $form['contact'] = array( + '#type' => 'details', + '#title' => t('Contact settings'), + '#open' => TRUE, + '#weight' => 0, + ); + $form['contact']['contact_default_status'] = array( + '#type' => 'checkbox', + '#title' => t('Enable the personal contact form by default for new users'), + '#description' => t('Changing this setting will not affect existing users.'), + // @see \Drupal\Core\Form\ConfigFormBase::config() + '#default_value' => $this->config('contact.settings')->get('user_default_enabled'), + ); + } + + /** + * {@inheritdoc} + */ + public function validate(array &$form, FormStateInterface $form_state) { + // No validations to perform. + } + + /** + * {@inheritdoc} + */ + public function submit(array &$form, FormStateInterface $form_state) { + $this->config('contact.settings') + ->set('user_default_enabled', $form_state->getValue('contact_default_status')) + ->save(); + } + +} diff --git a/core/modules/contact/src/Form/UserFormAlter.php b/core/modules/contact/src/Form/UserFormAlter.php new file mode 100644 index 0000000..837bb52 --- /dev/null +++ b/core/modules/contact/src/Form/UserFormAlter.php @@ -0,0 +1,91 @@ +currentUser = $current_user; + $this->userData = $user_data; + $this->configFactory = $config_factory; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('current_user'), + $container->get('user.data'), + $container->get('config.factory') + ); + } + + /** + * {@inheritdoc} + */ + public function alter(array &$form, FormStateInterface $form_state) { + $form['contact'] = array( + '#type' => 'details', + '#title' => t('Contact settings'), + '#open' => TRUE, + '#weight' => 5, + ); + $account = $form_state->getFormObject()->getEntity(); + if (!$this->currentUser->isAnonymous() && $account->id()) { + $account_data = $this->userData->get('contact', $account->id(), 'enabled'); + } + $form['contact']['contact'] = array( + '#type' => 'checkbox', + '#title' => t('Personal contact form'), + '#default_value' => isset($account_data) ? $account_data : $this->configFactory->get('contact.settings')->get('user_default_enabled'), + '#description' => t('Allow other users to contact you via a personal contact form which keeps your email address hidden. Note that some privileged users such as site administrators are still able to contact you even if you choose to disable this feature.'), + ); + } + + /** + * {@inheritdoc} + */ + public function validate(array &$form, FormStateInterface $form_state) { + // No validations to perform. + } + + /** + * {@inheritdoc} + */ + public function submit(array &$form, FormStateInterface $form_state) { + $account = $form_state->getFormObject()->getEntity(); + if ($account->id() && $form_state->hasValue('contact')) { + $this->userData->set('contact', $account->id(), 'enabled', (int) $form_state->getValue('contact')); + } + } + +} diff --git a/core/modules/dblog/dblog.module b/core/modules/dblog/dblog.module index 0714264..3dccaff 100644 --- a/core/modules/dblog/dblog.module +++ b/core/modules/dblog/dblog.module @@ -94,23 +94,8 @@ function _dblog_get_message_types() { * Implements hook_form_FORM_ID_alter() for system_logging_settings(). */ function dblog_form_system_logging_settings_alter(&$form, FormStateInterface $form_state) { - $row_limits = array(100, 1000, 10000, 100000, 1000000); - $form['dblog_row_limit'] = array( - '#type' => 'select', - '#title' => t('Database log messages to keep'), - '#default_value' => $form_state->config('dblog.settings')->get('row_limit'), - '#options' => array(0 => t('All')) + array_combine($row_limits, $row_limits), - '#description' => t('The maximum number of messages to keep in the database log. Requires a cron maintenance task.', array('@cron' => \Drupal::url('system.status'))) - ); - - $form['#submit'][] = 'dblog_logging_settings_submit'; -} - -/** - * Form submission handler for system_logging_settings(). - * - * @see dblog_form_system_logging_settings_alter() - */ -function dblog_logging_settings_submit($form, FormStateInterface $form_state) { - $form_state->config('dblog.settings')->set('row_limit', $form_state->getValue('dblog_row_limit'))->save(); + /** @var \Drupal\dblog\Form\SystemLoggingSettingsFormAlter $alter */ + $alter = \Drupal::resolve('Drupal\dblog\Form\SystemLoggingSettingsFormAlter'); + $alter->alter($form, $form_state); + $form['#submit'][] = array($alter, 'submit'); } diff --git a/core/modules/dblog/src/Form/SystemLoggingSettingsFormAlter.php b/core/modules/dblog/src/Form/SystemLoggingSettingsFormAlter.php new file mode 100644 index 0000000..1af5242 --- /dev/null +++ b/core/modules/dblog/src/Form/SystemLoggingSettingsFormAlter.php @@ -0,0 +1,74 @@ +configFactory = $config_factory; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('config.factory') + ); + } + + /** + * {@inheritdoc} + */ + protected function getEditableConfigNames() { + return ['dblog.settings']; + } + + /** + * {@inheritdoc} + */ + public function alter(array &$form, FormStateInterface $form_state) { + $row_limits = array(100, 1000, 10000, 100000, 1000000); + $form['dblog_row_limit'] = array( + '#type' => 'select', + '#title' => t('Database log messages to keep'), + '#default_value' => $this->config('dblog.settings')->get('row_limit'), + '#options' => array(0 => t('All')) + array_combine($row_limits, $row_limits), + '#description' => t('The maximum number of messages to keep in the database log. Requires a cron maintenance task.', array('@cron' => \Drupal::url('system.status'))) + ); + } + + /** + * {@inheritdoc} + */ + public function validate(array &$form, FormStateInterface $form_state) { + // No validations to perform. + } + + /** + * {@inheritdoc} + */ + public function submit(array &$form, FormStateInterface $form_state) { + $this->config('dblog.settings')->set('row_limit', $form_state->getValue('dblog_row_limit'))->save(); + } + +} diff --git a/core/modules/forum/src/ForumSettingsForm.php b/core/modules/forum/src/ForumSettingsForm.php index 77f176d..f2b43c4 100644 --- a/core/modules/forum/src/ForumSettingsForm.php +++ b/core/modules/forum/src/ForumSettingsForm.php @@ -25,6 +25,13 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['forum.settings']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('forum.settings'); diff --git a/core/modules/language/src/Form/ContentLanguageSettingsForm.php b/core/modules/language/src/Form/ContentLanguageSettingsForm.php index 1e89850..a7151fe 100644 --- a/core/modules/language/src/Form/ContentLanguageSettingsForm.php +++ b/core/modules/language/src/Form/ContentLanguageSettingsForm.php @@ -7,9 +7,8 @@ namespace Drupal\language\Form; -use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\Core\Form\ConfigFormBase; +use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\language\Entity\ContentLanguageSettings; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -17,7 +16,7 @@ /** * Configure the content language settings for this site. */ -class ContentLanguageSettingsForm extends ConfigFormBase { +class ContentLanguageSettingsForm extends FormBase { /** * The entity manager. @@ -29,14 +28,10 @@ class ContentLanguageSettingsForm extends ConfigFormBase { /** * Constructs a ContentLanguageSettingsForm object. * - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The config factory. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager. */ - public function __construct(ConfigFactoryInterface $config_factory, EntityManagerInterface $entity_manager) { - parent::__construct($config_factory); - + public function __construct(EntityManagerInterface $entity_manager) { $this->entityManager = $entity_manager; } @@ -45,7 +40,6 @@ public function __construct(ConfigFactoryInterface $config_factory, EntityManage */ public static function create(ContainerInterface $container) { return new static( - $container->get('config.factory'), $container->get('entity.manager') ); } diff --git a/core/modules/language/src/Form/NegotiationBrowserForm.php b/core/modules/language/src/Form/NegotiationBrowserForm.php index 8cbac11..eb2f0b7 100644 --- a/core/modules/language/src/Form/NegotiationBrowserForm.php +++ b/core/modules/language/src/Form/NegotiationBrowserForm.php @@ -56,6 +56,13 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['language.mappings']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $form = array(); diff --git a/core/modules/language/src/Form/NegotiationConfigureForm.php b/core/modules/language/src/Form/NegotiationConfigureForm.php index ca20801..d9cf420 100644 --- a/core/modules/language/src/Form/NegotiationConfigureForm.php +++ b/core/modules/language/src/Form/NegotiationConfigureForm.php @@ -121,6 +121,13 @@ public function getFormID() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['language.types']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $configurable = $this->languageTypes->get('configurable'); diff --git a/core/modules/language/src/Form/NegotiationSelectedForm.php b/core/modules/language/src/Form/NegotiationSelectedForm.php index 5b5d5a9..57194f9 100644 --- a/core/modules/language/src/Form/NegotiationSelectedForm.php +++ b/core/modules/language/src/Form/NegotiationSelectedForm.php @@ -26,6 +26,13 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['language.negotiation']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('language.negotiation'); $form['selected_langcode'] = array( diff --git a/core/modules/language/src/Form/NegotiationSessionForm.php b/core/modules/language/src/Form/NegotiationSessionForm.php index a0bd777..fff1dd5 100644 --- a/core/modules/language/src/Form/NegotiationSessionForm.php +++ b/core/modules/language/src/Form/NegotiationSessionForm.php @@ -25,6 +25,13 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['language.negotiation']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('language.negotiation'); $form['language_negotiation_session_param'] = array( diff --git a/core/modules/language/src/Form/NegotiationUrlForm.php b/core/modules/language/src/Form/NegotiationUrlForm.php index dcb721a..bf7ce2a 100644 --- a/core/modules/language/src/Form/NegotiationUrlForm.php +++ b/core/modules/language/src/Form/NegotiationUrlForm.php @@ -26,6 +26,13 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['language.negotiation']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { global $base_url; $config = $this->config('language.negotiation'); diff --git a/core/modules/locale/src/Form/LocaleSettingsForm.php b/core/modules/locale/src/Form/LocaleSettingsForm.php index 16c2087..4ff2c33 100644 --- a/core/modules/locale/src/Form/LocaleSettingsForm.php +++ b/core/modules/locale/src/Form/LocaleSettingsForm.php @@ -24,6 +24,13 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['locale.settings']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('locale.settings'); diff --git a/core/modules/simpletest/src/Form/SimpletestSettingsForm.php b/core/modules/simpletest/src/Form/SimpletestSettingsForm.php index d4e7197..e6d4d4d 100644 --- a/core/modules/simpletest/src/Form/SimpletestSettingsForm.php +++ b/core/modules/simpletest/src/Form/SimpletestSettingsForm.php @@ -25,6 +25,13 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['simpletest.settings']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('simpletest.settings'); $form['general'] = array( diff --git a/core/modules/statistics/src/StatisticsSettingsForm.php b/core/modules/statistics/src/StatisticsSettingsForm.php index 47411d7..2213bef 100644 --- a/core/modules/statistics/src/StatisticsSettingsForm.php +++ b/core/modules/statistics/src/StatisticsSettingsForm.php @@ -58,6 +58,13 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['statistics.settings']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('statistics.settings'); diff --git a/core/modules/system/src/Form/CronForm.php b/core/modules/system/src/Form/CronForm.php index cfb82fd..f906c70 100644 --- a/core/modules/system/src/Form/CronForm.php +++ b/core/modules/system/src/Form/CronForm.php @@ -83,6 +83,13 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['system.cron']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('system.cron'); diff --git a/core/modules/system/src/Form/FileSystemForm.php b/core/modules/system/src/Form/FileSystemForm.php index 8cf5eb3..368f318 100644 --- a/core/modules/system/src/Form/FileSystemForm.php +++ b/core/modules/system/src/Form/FileSystemForm.php @@ -74,6 +74,13 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['system.file']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('system.file'); $form['file_public_path'] = array( diff --git a/core/modules/system/src/Form/ImageToolkitForm.php b/core/modules/system/src/Form/ImageToolkitForm.php index 6eeaa4e..0d9bec9 100644 --- a/core/modules/system/src/Form/ImageToolkitForm.php +++ b/core/modules/system/src/Form/ImageToolkitForm.php @@ -61,6 +61,13 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['system.image']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $current_toolkit = $this->config('system.image')->get('toolkit'); diff --git a/core/modules/system/src/Form/LoggingForm.php b/core/modules/system/src/Form/LoggingForm.php index 500fed0..cfbbddc 100644 --- a/core/modules/system/src/Form/LoggingForm.php +++ b/core/modules/system/src/Form/LoggingForm.php @@ -25,6 +25,13 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['system.logging']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('system.logging'); $form['error_level'] = array( diff --git a/core/modules/system/src/Form/PerformanceForm.php b/core/modules/system/src/Form/PerformanceForm.php index 372b319..9049c78 100644 --- a/core/modules/system/src/Form/PerformanceForm.php +++ b/core/modules/system/src/Form/PerformanceForm.php @@ -93,6 +93,13 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['system.performance']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $form['#attached']['library'][] = 'system/drupal.system'; diff --git a/core/modules/system/src/Form/RegionalForm.php b/core/modules/system/src/Form/RegionalForm.php index 2d3934f..827f74f 100644 --- a/core/modules/system/src/Form/RegionalForm.php +++ b/core/modules/system/src/Form/RegionalForm.php @@ -58,6 +58,13 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['system.date']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $countries = $this->countryManager->getList(); $system_date = $this->config('system.date'); diff --git a/core/modules/system/src/Form/RssFeedsForm.php b/core/modules/system/src/Form/RssFeedsForm.php index 84f18fa..cde9964 100644 --- a/core/modules/system/src/Form/RssFeedsForm.php +++ b/core/modules/system/src/Form/RssFeedsForm.php @@ -25,6 +25,13 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['system.rss']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $rss_config = $this->config('system.rss'); $form['feed_description'] = array( diff --git a/core/modules/system/src/Form/SiteInformationForm.php b/core/modules/system/src/Form/SiteInformationForm.php index f2efcd5..71a0fbd 100644 --- a/core/modules/system/src/Form/SiteInformationForm.php +++ b/core/modules/system/src/Form/SiteInformationForm.php @@ -71,6 +71,13 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['system.site']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $site_config = $this->config('system.site'); $site_mail = $site_config->get('mail'); diff --git a/core/modules/system/src/Form/SiteMaintenanceModeForm.php b/core/modules/system/src/Form/SiteMaintenanceModeForm.php index b87533e..cde1f57 100644 --- a/core/modules/system/src/Form/SiteMaintenanceModeForm.php +++ b/core/modules/system/src/Form/SiteMaintenanceModeForm.php @@ -57,6 +57,13 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['system.maintenance']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('system.maintenance'); $form['maintenance_mode'] = array( diff --git a/core/modules/system/src/Form/ThemeAdminForm.php b/core/modules/system/src/Form/ThemeAdminForm.php index 93cace8..9aa7123 100644 --- a/core/modules/system/src/Form/ThemeAdminForm.php +++ b/core/modules/system/src/Form/ThemeAdminForm.php @@ -24,6 +24,13 @@ public function getFormID() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['system.theme']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state, array $theme_options = NULL) { // Administration theme settings. $form['admin_theme'] = array( diff --git a/core/modules/system/src/Form/ThemeSettingsForm.php b/core/modules/system/src/Form/ThemeSettingsForm.php index 8e72246..d096263 100644 --- a/core/modules/system/src/Form/ThemeSettingsForm.php +++ b/core/modules/system/src/Form/ThemeSettingsForm.php @@ -30,6 +30,13 @@ class ThemeSettingsForm extends ConfigFormBase { protected $moduleHandler; /** + * An array of configuration names that should be editable. + * + * @var array + */ + protected $editableConfig = []; + + /** * Constructs a ThemeSettingsForm object. * * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory @@ -62,6 +69,13 @@ public function getFormId() { /** * {@inheritdoc} + */ + protected function getEditableConfigNames() { + return $this->editableConfig; + } + + /** + * {@inheritdoc} * * @param string $theme * The theme name. @@ -87,6 +101,9 @@ public function buildForm(array $form, FormStateInterface $form_state, $theme = $var = 'theme_settings'; $config_key = 'system.theme.global'; } + // @todo this is pretty meaningless since we're using theme_get_settings + // which means overrides can bleed into active config here. + $this->editableConfig = [$config_key]; $form['var'] = array( '#type' => 'hidden', @@ -377,7 +394,9 @@ public function validateForm(array &$form, FormStateInterface $form_state) { public function submitForm(array &$form, FormStateInterface $form_state) { parent::submitForm($form, $form_state); - $config = $this->config($form_state->getValue('config_key')); + $config_key = $form_state->getValue('config_key'); + $this->editableConfig = [$config_key]; + $config = $this->config($config_key); // Exclude unnecessary elements before saving. $form_state->cleanValues(); diff --git a/core/modules/system/tests/modules/form_test/src/FormTestArgumentsObject.php b/core/modules/system/tests/modules/form_test/src/FormTestArgumentsObject.php index 182cd95..9dc522c 100644 --- a/core/modules/system/tests/modules/form_test/src/FormTestArgumentsObject.php +++ b/core/modules/system/tests/modules/form_test/src/FormTestArgumentsObject.php @@ -26,6 +26,13 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['form_test.object']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state, $arg = NULL) { $form['element'] = array('#markup' => 'The FormTestArgumentsObject::buildForm() method was used for this form.'); diff --git a/core/modules/system/tests/modules/form_test/src/FormTestControllerObject.php b/core/modules/system/tests/modules/form_test/src/FormTestControllerObject.php index d0599c7..47e5169 100644 --- a/core/modules/system/tests/modules/form_test/src/FormTestControllerObject.php +++ b/core/modules/system/tests/modules/form_test/src/FormTestControllerObject.php @@ -26,6 +26,13 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['form_test.object']; + } + + /** + * {@inheritdoc} + */ public static function create(ContainerInterface $container) { drupal_set_message(t('The FormTestControllerObject::create() method was used for this form.')); return new static( diff --git a/core/modules/system/tests/modules/form_test/src/FormTestObject.php b/core/modules/system/tests/modules/form_test/src/FormTestObject.php index 531401a..73f273e 100644 --- a/core/modules/system/tests/modules/form_test/src/FormTestObject.php +++ b/core/modules/system/tests/modules/form_test/src/FormTestObject.php @@ -25,6 +25,13 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['form_test.object']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $form['element'] = array('#markup' => 'The FormTestObject::buildForm() method was used for this form.'); diff --git a/core/modules/system/tests/modules/form_test/src/FormTestServiceObject.php b/core/modules/system/tests/modules/form_test/src/FormTestServiceObject.php index ea826e8..c60b6d1 100644 --- a/core/modules/system/tests/modules/form_test/src/FormTestServiceObject.php +++ b/core/modules/system/tests/modules/form_test/src/FormTestServiceObject.php @@ -25,6 +25,13 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['form_test.object']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $form['element'] = array('#markup' => 'The FormTestServiceObject::buildForm() method was used for this form.'); diff --git a/core/modules/system/tests/modules/form_test/src/SystemConfigFormTestForm.php b/core/modules/system/tests/modules/form_test/src/SystemConfigFormTestForm.php index 45efda7..243a81b 100644 --- a/core/modules/system/tests/modules/form_test/src/SystemConfigFormTestForm.php +++ b/core/modules/system/tests/modules/form_test/src/SystemConfigFormTestForm.php @@ -21,4 +21,11 @@ public function getFormId() { return 'form_test_system_config_test_form'; } + /** + * {@inheritdoc} + */ + protected function getEditableConfigNames() { + return []; + } + } diff --git a/core/modules/update/src/UpdateSettingsForm.php b/core/modules/update/src/UpdateSettingsForm.php index 81ef7e0..7e4664d 100644 --- a/core/modules/update/src/UpdateSettingsForm.php +++ b/core/modules/update/src/UpdateSettingsForm.php @@ -25,6 +25,13 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['update.settings']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('update.settings'); diff --git a/core/modules/user/src/AccountSettingsForm.php b/core/modules/user/src/AccountSettingsForm.php index bce6a60..2b91877 100644 --- a/core/modules/user/src/AccountSettingsForm.php +++ b/core/modules/user/src/AccountSettingsForm.php @@ -59,6 +59,17 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return [ + 'system.site', + 'user.mail', + 'user.settings', + ]; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $form = parent::buildForm($form, $form_state); $config = $this->config('user.settings'); diff --git a/core/modules/views_ui/src/Form/AdvancedSettingsForm.php b/core/modules/views_ui/src/Form/AdvancedSettingsForm.php index a9ffd6f..d8cd1e2 100644 --- a/core/modules/views_ui/src/Form/AdvancedSettingsForm.php +++ b/core/modules/views_ui/src/Form/AdvancedSettingsForm.php @@ -26,6 +26,13 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['views.settings']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $form = parent::buildForm($form, $form_state); diff --git a/core/modules/views_ui/src/Form/BasicSettingsForm.php b/core/modules/views_ui/src/Form/BasicSettingsForm.php index 621f1a4..91b8d60 100644 --- a/core/modules/views_ui/src/Form/BasicSettingsForm.php +++ b/core/modules/views_ui/src/Form/BasicSettingsForm.php @@ -25,6 +25,13 @@ public function getFormId() { /** * {@inheritdoc} */ + protected function getEditableConfigNames() { + return ['views.settings']; + } + + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { $form = parent::buildForm($form, $form_state);