From f1e2d9c055d4b5f282b647231445f0948bbedf98 Mon Sep 17 00:00:00 2001
From: webchick <webchick@24967.no-reply.drupal.org>
Date: Tue, 27 Aug 2013 23:44:11 -0700
Subject: [PATCH] Issue #1987810 by nick_schuch, dawehner, vijaycs85,
 tim.plunkett: Convert system_admin_config_page() to a new style controller.

---
 .../system/Controller/SystemController.php    | 113 +++++++++++++++++-
 core/modules/system/system.admin.inc          |  56 +--------
 core/modules/system/system.module             |   4 +-
 core/modules/system/system.routing.yml        |   7 ++
 4 files changed, 117 insertions(+), 63 deletions(-)

diff --git a/core/modules/system/lib/Drupal/system/Controller/SystemController.php b/core/modules/system/lib/Drupal/system/Controller/SystemController.php
index 7054e953fb6b..f73635363b0c 100644
--- a/core/modules/system/lib/Drupal/system/Controller/SystemController.php
+++ b/core/modules/system/lib/Drupal/system/Controller/SystemController.php
@@ -7,21 +7,124 @@
 
 namespace Drupal\system\Controller;
 
+use Drupal\Core\Controller\ControllerBase;
 use Drupal\Core\Controller\ControllerInterface;
+use Drupal\Core\Entity\Query\QueryFactory;
+use Drupal\system\SystemManager;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\HttpFoundation\RedirectResponse;
 
-
 /**
  * Returns responses for System routes.
  */
-class SystemController implements ControllerInterface {
+class SystemController extends ControllerBase implements ControllerInterface {
+
+  /**
+   * The entity query factory object.
+   *
+   * @var \Drupal\Core\Entity\Query\QueryFactory
+   */
+  protected $queryFactory;
+
+  /**
+   * System Manager Service.
+   *
+   * @var \Drupal\system\SystemManager
+   */
+  protected $systemManager;
+
+  /**
+   * Constructs a new ConfigController.
+   *
+   * @param \Drupal\system\SystemManager $systemManager
+   *   System manager service.
+   * @param \Drupal\Core\Entity\Query\QueryFactory $queryFactory
+   *   The entity query object.
+   */
+  public function __construct(SystemManager $systemManager, QueryFactory $queryFactory) {
+    $this->systemManager = $systemManager;
+    $this->queryFactory = $queryFactory;
+  }
 
   /**
    * {@inheritdoc}
    */
   public static function create(ContainerInterface $container) {
-    return new static();
+    return new static(
+      $container->get('system.manager'),
+      $container->get('entity.query')
+    );
+  }
+
+  /**
+   * Provide the administration overview page.
+   *
+   * @return array
+   *   A renderable array of the administration overview page.
+   */
+  public function overview() {
+    // Check for status report errors.
+    if ($this->systemManager->checkRequirements() && $this->currentUser()->hasPermission('administer site configuration')) {
+      drupal_set_message($this->t('One or more problems were detected with your Drupal installation. Check the <a href="@status">status report</a> for more information.', array('@status' => url('admin/reports/status'))), 'error');
+    }
+    $blocks = array();
+    // Load all links on admin/config and menu links below it.
+    $query = $this->queryFactory->get('menu_link')
+      ->condition('link_path', 'admin/config')
+      ->condition('module', 'system');
+    $result = $query->execute();
+    $menu_link_storage = $this->entityManager()->getStorageController('menu_link');
+    if ($system_link = $menu_link_storage->loadMultiple($result)) {
+      $system_link = reset($system_link);
+      $query = $this->queryFactory->get('menu_link')
+        ->condition('link_path', 'admin/help', '<>')
+        ->condition('menu_name', $system_link->menu_name)
+        ->condition('plid', $system_link->id())
+        ->condition('hidden', 0);
+      $result = $query->execute();
+      if (!empty($result)) {
+        $menu_links = $menu_link_storage->loadMultiple($result);
+        foreach ($menu_links as $item) {
+          _menu_link_translate($item);
+          if (!$item['access']) {
+            continue;
+          }
+          // The link description, either derived from 'description' in hook_menu()
+          // or customized via menu module is used as title attribute.
+          if (!empty($item['localized_options']['attributes']['title'])) {
+            $item['description'] = $item['localized_options']['attributes']['title'];
+            unset($item['localized_options']['attributes']['title']);
+          }
+          $block = $item;
+          // @todo Replace system_admin_menu_block() in
+          //   https://drupal.org/node/1987814.
+          $block['content'] = array(
+            '#theme' => 'admin_block_content',
+            '#content' => system_admin_menu_block($item),
+          );
+
+          if (!empty($block['content'])) {
+            $block['show'] = TRUE;
+          }
+
+          // Prepare for sorting as in function _menu_tree_check_access().
+          // The weight is offset so it is always positive, with a uniform 5-digits.
+          $blocks[(50000 + $item['weight']) . ' ' . $item['title'] . ' ' . $item['mlid']] = $block;
+        }
+      }
+    }
+    if ($blocks) {
+      ksort($blocks);
+      return array(
+        '#theme' => 'admin_page',
+        '#blocks' => $blocks,
+      );
+    }
+    else {
+      return array(
+        '#markup' => $this->t('You do not have any administrative items.'),
+      );
+    }
   }
 
   /**
@@ -32,9 +135,9 @@ public static function create(ContainerInterface $container) {
    *
    * @return \Symfony\Component\HttpFoundation\RedirectResponse
    */
-  function compactPage($mode) {
+  public function compactPage($mode) {
     user_cookie_save(array('admin_compact_mode' => ($mode == 'on')));
-    return new RedirectResponse(url('<front>', array('absolute' => TRUE)));
+    return $this->redirect('front');
   }
 
 }
diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc
index 050cdd76cc21..df7ef6f9a523 100644
--- a/core/modules/system/system.admin.inc
+++ b/core/modules/system/system.admin.inc
@@ -10,60 +10,6 @@
 use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
 
-/**
- * Menu callback; Provide the administration overview page.
- */
-function system_admin_config_page() {
-  // Check for status report errors.
-  // @todo Use depedancy injection in http://drupal.org/node/1987810.
-  if (Drupal::service('system.manager')->checkRequirements() && user_access('administer site configuration')) {
-    drupal_set_message(t('One or more problems were detected with your Drupal installation. Check the <a href="@status">status report</a> for more information.', array('@status' => url('admin/reports/status'))), 'error');
-  }
-  $blocks = array();
-  if ($system_link = entity_load_multiple_by_properties('menu_link', array('link_path' => 'admin/config', 'module' => 'system'))) {
-    $system_link = reset($system_link);
-    $query = Drupal::entityQuery('menu_link')
-      ->condition('link_path', 'admin/help', '<>')
-      ->condition('menu_name', $system_link->menu_name)
-      ->condition('plid', $system_link->id())
-      ->condition('hidden', 0);
-    $result = $query->execute();
-    if (!empty($result)) {
-      $menu_links = menu_link_load_multiple($result);
-
-      foreach ($menu_links as $item) {
-        _menu_link_translate($item);
-        if (!$item['access']) {
-          continue;
-        }
-        // The link description, either derived from 'description' in hook_menu()
-        // or customized via menu module is used as title attribute.
-        if (!empty($item['localized_options']['attributes']['title'])) {
-          $item['description'] = $item['localized_options']['attributes']['title'];
-          unset($item['localized_options']['attributes']['title']);
-        }
-        $block = $item;
-        $block['content'] = '';
-        $block['content'] .= theme('admin_block_content', array('content' => system_admin_menu_block($item)));
-        if (!empty($block['content'])) {
-          $block['show'] = TRUE;
-        }
-
-        // Prepare for sorting as in function _menu_tree_check_access().
-        // The weight is offset so it is always positive, with a uniform 5-digits.
-        $blocks[(50000 + $item['weight']) . ' ' . $item['title'] . ' ' . $item['mlid']] = $block;
-      }
-    }
-  }
-  if ($blocks) {
-    ksort($blocks);
-    return theme('admin_page', array('blocks' => $blocks));
-  }
-  else {
-    return t('You do not have any administrative items.');
-  }
-}
-
 /**
  * Provide a single block from the administration menu as a page.
  *
@@ -400,7 +346,7 @@ function theme_admin_block($variables) {
     $output .= '<h3>' . $block['title'] . '</h3>';
   }
   if (!empty($block['content'])) {
-    $output .= '<div class="body">' . $block['content'] . '</div>';
+    $output .= '<div class="body">' . render($block['content']) . '</div>';
   }
   else {
     $output .= '<div class="description">' . $block['description'] . '</div>';
diff --git a/core/modules/system/system.module b/core/modules/system/system.module
index bd58f930e367..94fbd21bc491 100644
--- a/core/modules/system/system.module
+++ b/core/modules/system/system.module
@@ -727,9 +727,7 @@ function system_menu() {
   $items['admin/config'] = array(
     'title' => 'Configuration',
     'description' => 'Administer settings.',
-    'page callback' => 'system_admin_config_page',
-    'access arguments' => array('access administration pages'),
-    'file' => 'system.admin.inc',
+    'route_name' => 'system_admin_config',
   );
 
   // Media settings.
diff --git a/core/modules/system/system.routing.yml b/core/modules/system/system.routing.yml
index f12ba8aa2751..9b27c08de09d 100644
--- a/core/modules/system/system.routing.yml
+++ b/core/modules/system/system.routing.yml
@@ -227,3 +227,10 @@ system_timezone:
     _controller: '\Drupal\system\Controller\TimezoneController::getTimezone'
   requirements:
     _access: 'TRUE'
+
+system_admin_config:
+  pattern: '/admin/config'
+  defaults:
+    _content: '\Drupal\system\Controller\SystemController::overview'
+  requirements:
+    _permission: 'access administration pages'
-- 
GitLab