SystemController.php 4.54 KB
Newer Older
1 2 3 4 5 6 7 8 9
<?php

/**
 * @file
 * Contains \Drupal\system\Controller\SystemController.
 */

namespace Drupal\system\Controller;

10
use Drupal\Core\Controller\ControllerBase;
11
use Drupal\Core\Controller\ControllerInterface;
12 13
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\system\SystemManager;
14 15 16 17 18 19
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;

/**
 * Returns responses for System routes.
 */
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
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;
  }
48 49 50 51 52

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
    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.'),
      );
    }
128 129 130 131 132 133 134 135 136 137
  }

  /**
   * Sets whether the admin menu is in compact mode or not.
   *
   * @param string $mode
   *   Valid values are 'on' and 'off'.
   *
   * @return \Symfony\Component\HttpFoundation\RedirectResponse
   */
138
  public function compactPage($mode) {
139
    user_cookie_save(array('admin_compact_mode' => ($mode == 'on')));
140
    return $this->redirect('front');
141 142 143
  }

}