From c4fa3478cf04d15d3e6b67bea9e9b09948079dad Mon Sep 17 00:00:00 2001
From: webchick <webchick@24967.no-reply.drupal.org>
Date: Sun, 17 Mar 2013 00:48:32 -0700
Subject: [PATCH] Issue #1937998 by ACF, amateescu: Convert update's
 system_config_form() to SystemConfigFormBase.

---
 .../lib/Drupal/update/UpdateSettingsForm.php  | 124 ++++++++++++++++++
 core/modules/update/update.module             |   4 +-
 core/modules/update/update.routing.yml        |   6 +
 core/modules/update/update.settings.inc       | 118 -----------------
 4 files changed, 131 insertions(+), 121 deletions(-)
 create mode 100644 core/modules/update/lib/Drupal/update/UpdateSettingsForm.php
 create mode 100644 core/modules/update/update.routing.yml
 delete mode 100644 core/modules/update/update.settings.inc

diff --git a/core/modules/update/lib/Drupal/update/UpdateSettingsForm.php b/core/modules/update/lib/Drupal/update/UpdateSettingsForm.php
new file mode 100644
index 000000000000..e1f906ea25ec
--- /dev/null
+++ b/core/modules/update/lib/Drupal/update/UpdateSettingsForm.php
@@ -0,0 +1,124 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\update\UpdateSettingsForm.
+ */
+
+namespace Drupal\update;
+
+use Drupal\system\SystemConfigFormBase;
+
+/**
+ * Configure update settings for this site.
+ */
+class UpdateSettingsForm extends SystemConfigFormBase {
+
+  /**
+   * Implements \Drupal\Core\Form\FormInterface::getFormID().
+   */
+  public function getFormID() {
+    return 'update_settings';
+  }
+
+  /**
+   * Implements \Drupal\Core\Form\FormInterface::buildForm().
+   */
+  public function buildForm(array $form, array &$form_state) {
+    $config = $this->configFactory->get('update.settings');
+
+    $form['update_check_frequency'] = array(
+      '#type' => 'radios',
+      '#title' => t('Check for updates'),
+      '#default_value' => $config->get('check.interval_days'),
+      '#options' => array(
+        '1' => t('Daily'),
+        '7' => t('Weekly'),
+      ),
+      '#description' => t('Select how frequently you want to automatically check for new releases of your currently installed modules and themes.'),
+    );
+
+    $form['update_check_disabled'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Check for updates of disabled modules and themes'),
+      '#default_value' => $config->get('check.disabled_extensions'),
+    );
+
+    $notification_emails = $config->get('notification.emails');
+    $form['update_notify_emails'] = array(
+      '#type' => 'textarea',
+      '#title' => t('E-mail addresses to notify when updates are available'),
+      '#rows' => 4,
+      '#default_value' => implode("\n", $notification_emails),
+      '#description' => t('Whenever your site checks for available updates and finds new releases, it can notify a list of users via e-mail. Put each address on a separate line. If blank, no e-mails will be sent.'),
+    );
+
+    $form['update_notification_threshold'] = array(
+      '#type' => 'radios',
+      '#title' => t('E-mail notification threshold'),
+      '#default_value' => $config->get('notification.threshold'),
+      '#options' => array(
+        'all' => t('All newer versions'),
+        'security' => t('Only security updates'),
+      ),
+      '#description' => t('You can choose to send e-mail only if a security update is available, or to be notified about all newer versions. If there are updates available of Drupal core or any of your installed modules and themes, your site will always print a message on the <a href="@status_report">status report</a> page, and will also display an error message on administration pages if there is a security update.', array('@status_report' => url('admin/reports/status')))
+    );
+
+    return parent::buildForm($form, $form_state);
+  }
+
+  /**
+   * Implements \Drupal\Core\Form\FormInterface::validateForm().
+   */
+  public function validateForm(array &$form, array &$form_state) {
+    $form_state['notify_emails'] = array();
+    if (!empty($form_state['values']['update_notify_emails'])) {
+      $valid = array();
+      $invalid = array();
+      foreach (explode("\n", trim($form_state['values']['update_notify_emails'])) as $email) {
+        $email = trim($email);
+        if (!empty($email)) {
+          if (valid_email_address($email)) {
+            $valid[] = $email;
+          }
+          else {
+            $invalid[] = $email;
+          }
+        }
+      }
+      if (empty($invalid)) {
+        $form_state['notify_emails'] = $valid;
+      }
+      elseif (count($invalid) == 1) {
+        form_set_error('update_notify_emails', t('%email is not a valid e-mail address.', array('%email' => reset($invalid))));
+      }
+      else {
+        form_set_error('update_notify_emails', t('%emails are not valid e-mail addresses.', array('%emails' => implode(', ', $invalid))));
+      }
+    }
+
+    parent::validateForm($form, $form_state);
+  }
+
+  /**
+   * Implements \Drupal\Core\Form\FormInterface::submitForm().
+   */
+  public function submitForm(array &$form, array &$form_state) {
+    $config = $this->configFactory->get('update.settings');
+     // See if the update_check_disabled setting is being changed, and if so,
+    // invalidate all cached update status data.
+    if ($form_state['values']['update_check_disabled'] != $config->get('check.disabled_extensions')) {
+      _update_cache_clear();
+    }
+
+    $config
+      ->set('check.disabled_extensions', $form_state['values']['update_check_disabled'])
+      ->set('check.interval_days', $form_state['values']['update_check_frequency'])
+      ->set('notification.emails', $form_state['notify_emails'])
+      ->set('notification.threshold', $form_state['values']['update_notification_threshold'])
+      ->save();
+
+    parent::submitForm($form, $form_state);
+  }
+
+}
diff --git a/core/modules/update/update.module b/core/modules/update/update.module
index 6f0f1e306f31..596e990a1142 100644
--- a/core/modules/update/update.module
+++ b/core/modules/update/update.module
@@ -170,10 +170,8 @@ function update_menu() {
   );
   $items['admin/reports/updates/settings'] = array(
     'title' => 'Settings',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('update_settings'),
+    'route_name' => 'update_settings',
     'access arguments' => array('administer site configuration'),
-    'file' => 'update.settings.inc',
     'type' => MENU_LOCAL_TASK,
     'weight' => 50,
   );
diff --git a/core/modules/update/update.routing.yml b/core/modules/update/update.routing.yml
new file mode 100644
index 000000000000..f201302d814c
--- /dev/null
+++ b/core/modules/update/update.routing.yml
@@ -0,0 +1,6 @@
+update_settings:
+  pattern: '/admin/reports/updates/settings'
+  defaults:
+    _form: '\Drupal\update\UpdateSettingsForm'
+  requirements:
+    _permission: 'administer site configuration'
diff --git a/core/modules/update/update.settings.inc b/core/modules/update/update.settings.inc
deleted file mode 100644
index 0a5e337b5eb6..000000000000
--- a/core/modules/update/update.settings.inc
+++ /dev/null
@@ -1,118 +0,0 @@
-<?php
-
-/**
- * @file
- * Code required only for the update status settings form.
- */
-
-/**
- * Form constructor for the update settings form.
- *
- * @see update_settings_validate()
- * @see update_settings_submit()
- * @ingroup forms
- */
-function update_settings($form, &$form_state) {
-  $config = config('update.settings');
-  $form['update_check_frequency'] = array(
-    '#type' => 'radios',
-    '#title' => t('Check for updates'),
-    '#default_value' => $config->get('check.interval_days'),
-    '#options' => array(
-      '1' => t('Daily'),
-      '7' => t('Weekly'),
-    ),
-    '#description' => t('Select how frequently you want to automatically check for new releases of your currently installed modules and themes.'),
-  );
-
-  $form['update_check_disabled'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Check for updates of disabled modules and themes'),
-    '#default_value' => $config->get('check.disabled_extensions'),
-  );
-
-  $notification_emails = $config->get('notification.emails');
-  $form['update_notify_emails'] = array(
-    '#type' => 'textarea',
-    '#title' => t('E-mail addresses to notify when updates are available'),
-    '#rows' => 4,
-    '#default_value' => implode("\n", $notification_emails),
-    '#description' => t('Whenever your site checks for available updates and finds new releases, it can notify a list of users via e-mail. Put each address on a separate line. If blank, no e-mails will be sent.'),
-  );
-
-  $form['update_notification_threshold'] = array(
-    '#type' => 'radios',
-    '#title' => t('E-mail notification threshold'),
-    '#default_value' => $config->get('notification.threshold'),
-    '#options' => array(
-      'all' => t('All newer versions'),
-      'security' => t('Only security updates'),
-    ),
-    '#description' => t('You can choose to send e-mail only if a security update is available, or to be notified about all newer versions. If there are updates available of Drupal core or any of your installed modules and themes, your site will always print a message on the <a href="@status_report">status report</a> page, and will also display an error message on administration pages if there is a security update.', array('@status_report' => url('admin/reports/status')))
-  );
-
-  return system_config_form($form, $form_state);
-}
-
-/**
- * Form validation handler for update_settings().
- *
- * Validates the e-mail addresses and ensures the field is formatted correctly.
- *
- * @see update_settings_submit()
- */
-function update_settings_validate($form, &$form_state) {
-  $form_state['notify_emails'] = array();
-  if (!empty($form_state['values']['update_notify_emails'])) {
-    $valid = array();
-    $invalid = array();
-    foreach (explode("\n", trim($form_state['values']['update_notify_emails'])) as $email) {
-      $email = trim($email);
-      if (!empty($email)) {
-        if (valid_email_address($email)) {
-          $valid[] = $email;
-        }
-        else {
-          $invalid[] = $email;
-        }
-      }
-    }
-    if (empty($invalid)) {
-      $form_state['notify_emails'] = $valid;
-    }
-    elseif (count($invalid) == 1) {
-      form_set_error('update_notify_emails', t('%email is not a valid e-mail address.', array('%email' => reset($invalid))));
-    }
-    else {
-      form_set_error('update_notify_emails', t('%emails are not valid e-mail addresses.', array('%emails' => implode(', ', $invalid))));
-    }
-  }
-}
-
-/**
- * Form submission handler for update_settings().
- *
- * Also invalidates the cache of available updates if the "Check for updates of
- * disabled modules and themes" setting is being changed. The available updates
- * report needs to refetch available update data after this setting changes or
- * it would show misleading things (e.g., listing the disabled projects on the
- * site with the "No available releases found" warning).
- *
- * @see update_settings_validate()
- */
-function update_settings_submit($form, $form_state) {
-  $config = config('update.settings');
-
-  // See if the update_check_disabled setting is being changed, and if so,
-  // invalidate all cached update status data.
-  if ($form_state['values']['update_check_disabled'] != $config->get('check.disabled_extensions')) {
-    _update_cache_clear();
-  }
-
-  $config
-    ->set('check.disabled_extensions', $form_state['values']['update_check_disabled'])
-    ->set('check.interval_days', $form_state['values']['update_check_frequency'])
-    ->set('notification.emails', $form_state['notify_emails'])
-    ->set('notification.threshold', $form_state['values']['update_notification_threshold'])
-    ->save();
-}
-- 
GitLab