From 76ca183141048fc62f5923d69d4af4c5859a5ae2 Mon Sep 17 00:00:00 2001
From: webchick <webchick@24967.no-reply.drupal.org>
Date: Sun, 17 Mar 2013 00:54:50 -0700
Subject: [PATCH] Issue #1938008 by bxtaylor, floretan: Convert menu.module's
 system_config_form() to SystemConfigFormBase.

---
 .../menu/lib/Drupal/menu/MenuSettingsForm.php | 72 +++++++++++++++++++
 core/modules/menu/menu.admin.inc              | 49 -------------
 core/modules/menu/menu.module                 |  4 +-
 core/modules/menu/menu.routing.yml            |  6 ++
 4 files changed, 79 insertions(+), 52 deletions(-)
 create mode 100644 core/modules/menu/lib/Drupal/menu/MenuSettingsForm.php
 create mode 100644 core/modules/menu/menu.routing.yml

diff --git a/core/modules/menu/lib/Drupal/menu/MenuSettingsForm.php b/core/modules/menu/lib/Drupal/menu/MenuSettingsForm.php
new file mode 100644
index 000000000000..6bcbba287472
--- /dev/null
+++ b/core/modules/menu/lib/Drupal/menu/MenuSettingsForm.php
@@ -0,0 +1,72 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\menu\MenuSettingsForm.
+ */
+
+namespace Drupal\menu;
+
+use Drupal\system\SystemConfigFormBase;
+
+/**
+ * Select the menus to be used for the main and secondary links for this site.
+ */
+class MenuSettingsForm extends SystemConfigFormBase {
+
+  /**
+   * Implements \Drupal\Core\Form\FormInterface::getFormID().
+   */
+  public function getFormID() {
+    return 'menu_configure';
+  }
+
+  /**
+   * Implements \Drupal\Core\Form\FormInterface::buildForm().
+   */
+  public function buildForm(array $form, array &$form_state) {
+    $config = $this->configFactory->get('menu.settings');
+    $form['intro'] = array(
+      '#type' => 'item',
+      '#markup' => t('The menu module allows on-the-fly creation of menu links in the content authoring forms. To configure these settings for a particular content type, visit the <a href="@content-types">Content types</a> page, click the <em>edit</em> link for the content type, and go to the <em>Menu settings</em> section.', array('@content-types' => url('admin/structure/types'))),
+    );
+
+    $menu_options = menu_get_menus();
+
+    $main = $config->get('main_links');
+    $form['menu_main_links_source'] = array(
+      '#type' => 'select',
+      '#title' => t('Source for the Main links'),
+      '#default_value' => $main,
+      '#empty_option' => t('No Main links'),
+      '#options' => $menu_options,
+      '#tree' => FALSE,
+      '#description' => t('Select what should be displayed as the Main links (typically at the top of the page).'),
+    );
+
+    $form['menu_secondary_links_source'] = array(
+      '#type' => 'select',
+      '#title' => t('Source for the Secondary links'),
+      '#default_value' => $config->get('secondary_links'),
+      '#empty_option' => t('No Secondary links'),
+      '#options' => $menu_options,
+      '#tree' => FALSE,
+      '#description' => t('Select the source for the Secondary links. An advanced option allows you to use the same source for both Main links (currently %main) and Secondary links: if your source menu has two levels of hierarchy, the top level menu links will appear in the Main links, and the children of the active link will appear in the Secondary links.', array('%main' => $main ? $menu_options[$main] : t('none'))),
+    );
+
+    return parent::buildForm($form, $form_state);
+  }
+
+  /**
+   * Implements \Drupal\Core\Form\FormInterface::submitForm().
+   */
+  public function submitForm(array &$form, array &$form_state) {
+    $this->configFactory->get('menu.settings')
+      ->set('main_links', $form_state['values']['menu_main_links_source'])
+      ->set('secondary_links', $form_state['values']['menu_secondary_links_source'])
+      ->save();
+
+    parent::submitForm($form, $form_state);
+  }
+
+}
diff --git a/core/modules/menu/menu.admin.inc b/core/modules/menu/menu.admin.inc
index 9ac32e253012..48558872c359 100644
--- a/core/modules/menu/menu.admin.inc
+++ b/core/modules/menu/menu.admin.inc
@@ -492,52 +492,3 @@ function menu_link_reset_form_submit($form, &$form_state) {
   drupal_set_message(t('The menu link was reset to its default settings.'));
   $form_state['redirect'] = 'admin/structure/menu/manage/' . $new_menu_link->menu_name;
 }
-
-/**
- * Menu callback; Build the form presenting menu configuration options.
- *
- * @ingroup forms
- * @see menu_configure_submit()
- */
-function menu_configure($form, &$form_state) {
-  $config = config('menu.settings');
-  $form['intro'] = array(
-    '#type' => 'item',
-    '#markup' => t('The menu module allows on-the-fly creation of menu links in the content authoring forms. To configure these settings for a particular content type, visit the <a href="@content-types">Content types</a> page, click the <em>edit</em> link for the content type, and go to the <em>Menu settings</em> section.', array('@content-types' => url('admin/structure/types'))),
-  );
-
-  $menu_options = menu_get_menus();
-
-  $main = $config->get('main_links');
-  $form['menu_main_links_source'] = array(
-    '#type' => 'select',
-    '#title' => t('Source for the Main links'),
-    '#default_value' => $main,
-    '#empty_option' => t('No Main links'),
-    '#options' => $menu_options,
-    '#tree' => FALSE,
-    '#description' => t('Select what should be displayed as the Main links (typically at the top of the page).'),
-  );
-
-  $form['menu_secondary_links_source'] = array(
-    '#type' => 'select',
-    '#title' => t('Source for the Secondary links'),
-    '#default_value' => $config->get('secondary_links'),
-    '#empty_option' => t('No Secondary links'),
-    '#options' => $menu_options,
-    '#tree' => FALSE,
-    '#description' => t('Select the source for the Secondary links. An advanced option allows you to use the same source for both Main links (currently %main) and Secondary links: if your source menu has two levels of hierarchy, the top level menu links will appear in the Main links, and the children of the active link will appear in the Secondary links.', array('%main' => $main ? $menu_options[$main] : t('none'))),
-  );
-
-  return system_config_form($form, $form_state);
-}
-
-/**
- * Form submission handler for menu_configure().
- */
-function menu_configure_submit($form, &$form_state) {
-  config('menu.settings')
-    ->set('main_links', $form_state['values']['menu_main_links_source'])
-    ->set('secondary_links', $form_state['values']['menu_secondary_links_source'])
-    ->save();
-}
diff --git a/core/modules/menu/menu.module b/core/modules/menu/menu.module
index a4a671893a0e..addca0f58aa2 100644
--- a/core/modules/menu/menu.module
+++ b/core/modules/menu/menu.module
@@ -92,12 +92,10 @@ function menu_menu() {
   );
   $items['admin/structure/menu/settings'] = array(
     'title' => 'Settings',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('menu_configure'),
+    'route_name' => 'menu_settings',
     'access arguments' => array('administer menu'),
     'type' => MENU_LOCAL_TASK,
     'weight' => 100,
-    'file' => 'menu.admin.inc',
   );
   $items['admin/structure/menu/manage/%menu'] = array(
     'title' => 'Edit menu',
diff --git a/core/modules/menu/menu.routing.yml b/core/modules/menu/menu.routing.yml
new file mode 100644
index 000000000000..9f2b4dacd623
--- /dev/null
+++ b/core/modules/menu/menu.routing.yml
@@ -0,0 +1,6 @@
+menu_settings:
+  pattern: '/admin/structure/menu/settings'
+  defaults:
+    _form: 'Drupal\menu\MenuSettingsForm'
+  requirements:
+    _permission: 'administer menu'
-- 
GitLab