View source
<?php
namespace Drupal\system\Controller;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Menu\MenuLinkTreeInterface;
use Drupal\Core\Menu\MenuTreeParameters;
use Drupal\Core\Theme\ThemeAccessCheck;
use Drupal\Core\Url;
use Drupal\system\SystemManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SystemController extends ControllerBase {
protected $queryFactory;
protected $systemManager;
protected $themeAccess;
protected $formBuilder;
protected $themeHandler;
protected $menuLinkTree;
public function __construct(SystemManager $systemManager, QueryFactory $queryFactory, ThemeAccessCheck $theme_access, FormBuilderInterface $form_builder, ThemeHandlerInterface $theme_handler, MenuLinkTreeInterface $menu_link_tree) {
$this->systemManager = $systemManager;
$this->queryFactory = $queryFactory;
$this->themeAccess = $theme_access;
$this->formBuilder = $form_builder;
$this->themeHandler = $theme_handler;
$this->menuLinkTree = $menu_link_tree;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('system.manager'), $container
->get('entity.query'), $container
->get('access_check.theme'), $container
->get('form_builder'), $container
->get('theme_handler'), $container
->get('menu.link_tree'));
}
public function overview($link_id) {
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' => $this
->url('system.status'),
)), 'error');
}
$parameters = new MenuTreeParameters();
$parameters
->setRoot($link_id)
->excludeRoot()
->setTopLevelOnly()
->onlyEnabledLinks();
$tree = $this->menuLinkTree
->load(NULL, $parameters);
$manipulators = array(
array(
'callable' => 'menu.default_tree_manipulators:checkAccess',
),
array(
'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
),
);
$tree = $this->menuLinkTree
->transform($tree, $manipulators);
$tree_access_cacheability = new CacheableMetadata();
$blocks = array();
foreach ($tree as $key => $element) {
$tree_access_cacheability = $tree_access_cacheability
->merge(CacheableMetadata::createFromObject($element->access));
if (!$element->access
->isAllowed()) {
continue;
}
$link = $element->link;
$block['title'] = $link
->getTitle();
$block['description'] = $link
->getDescription();
$block['content'] = array(
'#theme' => 'admin_block_content',
'#content' => $this->systemManager
->getAdminBlock($link),
);
if (!empty($block['content']['#content'])) {
$blocks[$key] = $block;
}
}
if ($blocks) {
ksort($blocks);
$build = [
'#theme' => 'admin_page',
'#blocks' => $blocks,
];
$tree_access_cacheability
->applyTo($build);
return $build;
}
else {
$build = [
'#markup' => $this
->t('You do not have any administrative items.'),
];
$tree_access_cacheability
->applyTo($build);
return $build;
}
}
public function compactPage($mode) {
user_cookie_save(array(
'admin_compact_mode' => $mode == 'on',
));
return $this
->redirect('<front>');
}
public function systemAdminMenuBlockPage() {
return $this->systemManager
->getBlockContents();
}
public function themesPage() {
$config = $this
->config('system.theme');
$themes = $this->themeHandler
->rebuildThemeData();
uasort($themes, 'system_sort_modules_by_info_name');
$theme_default = $config
->get('default');
$theme_groups = array(
'installed' => array(),
'uninstalled' => array(),
);
$admin_theme = $config
->get('admin');
$admin_theme_options = array();
foreach ($themes as &$theme) {
if (!empty($theme->info['hidden'])) {
continue;
}
$theme->is_default = $theme
->getName() == $theme_default;
$theme->is_admin = $theme
->getName() == $admin_theme || $theme->is_default && $admin_theme == '0';
$theme->screenshot = NULL;
if (isset($themes[$theme
->getName()]->base_themes)) {
$theme_keys = array_keys($themes[$theme
->getName()]->base_themes);
$theme_keys[] = $theme
->getName();
}
else {
$theme_keys = array(
$theme
->getName(),
);
}
foreach (array_reverse($theme_keys) as $theme_key) {
if (isset($themes[$theme_key]) && file_exists($themes[$theme_key]->info['screenshot'])) {
$theme->screenshot = array(
'uri' => $themes[$theme_key]->info['screenshot'],
'alt' => $this
->t('Screenshot for @theme theme', array(
'@theme' => $theme->info['name'],
)),
'title' => $this
->t('Screenshot for @theme theme', array(
'@theme' => $theme->info['name'],
)),
'attributes' => array(
'class' => array(
'screenshot',
),
),
);
break;
}
}
if (empty($theme->status)) {
$theme->incompatible_core = !isset($theme->info['core']) || $theme->info['core'] != \DRUPAL::CORE_COMPATIBILITY;
$theme->incompatible_region = !isset($theme->info['regions']['content']);
$theme->incompatible_php = version_compare(phpversion(), $theme->info['php']) < 0;
$theme->incompatible_base = isset($theme->info['base theme']) && !isset($themes[$theme->info['base theme']]);
$theme->incompatible_engine = isset($theme->info['engine']) && !isset($theme->owner);
}
$theme->operations = array();
if (!empty($theme->status) || !$theme->incompatible_core && !$theme->incompatible_php && !$theme->incompatible_base && !$theme->incompatible_engine) {
$query['theme'] = $theme
->getName();
if ($this->themeAccess
->checkAccess($theme
->getName())) {
$theme->operations[] = array(
'title' => $this
->t('Settings'),
'url' => Url::fromRoute('system.theme_settings_theme', [
'theme' => $theme
->getName(),
]),
'attributes' => array(
'title' => $this
->t('Settings for @theme theme', array(
'@theme' => $theme->info['name'],
)),
),
);
}
if (!empty($theme->status)) {
if (!$theme->is_default) {
$theme_uninstallable = TRUE;
if ($theme
->getName() == $admin_theme) {
$theme_uninstallable = FALSE;
}
foreach ($theme->required_by as $themename => $dependency) {
if (!empty($themes[$themename]->status)) {
$theme_uninstallable = FALSE;
}
}
if ($theme_uninstallable) {
$theme->operations[] = array(
'title' => $this
->t('Uninstall'),
'url' => Url::fromRoute('system.theme_uninstall'),
'query' => $query,
'attributes' => array(
'title' => $this
->t('Uninstall @theme theme', array(
'@theme' => $theme->info['name'],
)),
),
);
}
$theme->operations[] = array(
'title' => $this
->t('Set as default'),
'url' => Url::fromRoute('system.theme_set_default'),
'query' => $query,
'attributes' => array(
'title' => $this
->t('Set @theme as default theme', array(
'@theme' => $theme->info['name'],
)),
),
);
}
$admin_theme_options[$theme
->getName()] = $theme->info['name'];
}
else {
$theme->operations[] = array(
'title' => $this
->t('Install'),
'url' => Url::fromRoute('system.theme_install'),
'query' => $query,
'attributes' => array(
'title' => $this
->t('Install @theme theme', array(
'@theme' => $theme->info['name'],
)),
),
);
$theme->operations[] = array(
'title' => $this
->t('Install and set as default'),
'url' => Url::fromRoute('system.theme_set_default'),
'query' => $query,
'attributes' => array(
'title' => $this
->t('Install @theme as default theme', array(
'@theme' => $theme->info['name'],
)),
),
);
}
}
$theme->notes = array();
if ($theme->is_default) {
$theme->notes[] = $this
->t('default theme');
}
if ($theme->is_admin) {
$theme->notes[] = $this
->t('admin theme');
}
$theme_groups[$theme->status ? 'installed' : 'uninstalled'][] = $theme;
}
$theme_group_titles = array(
'installed' => $this
->formatPlural(count($theme_groups['installed']), 'Installed theme', 'Installed themes'),
);
if (!empty($theme_groups['uninstalled'])) {
$theme_group_titles['uninstalled'] = $this
->formatPlural(count($theme_groups['uninstalled']), 'Uninstalled theme', 'Uninstalled themes');
}
uasort($theme_groups['installed'], 'system_sort_themes');
$this
->moduleHandler()
->alter('system_themes_page', $theme_groups);
$build = array();
$build[] = array(
'#theme' => 'system_themes_page',
'#theme_groups' => $theme_groups,
'#theme_group_titles' => $theme_group_titles,
);
$build[] = $this->formBuilder
->getForm('Drupal\\system\\Form\\ThemeAdminForm', $admin_theme_options);
return $build;
}
}