class SystemController in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Controller/SystemController.php \Drupal\system\Controller\SystemController
Returns responses for System routes.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\system\Controller\SystemController
Expanded class hierarchy of SystemController
File
- core/
modules/ system/ src/ Controller/ SystemController.php, line 25 - Contains \Drupal\system\Controller\SystemController.
Namespace
Drupal\system\ControllerView source
class SystemController extends ControllerBase {
/**
* The entity query factory object.
*
* @var \Drupal\Core\Entity\Query\QueryFactory
*/
protected $queryFactory;
/**
* System Manager Service.
*
* @var \Drupal\system\SystemManager
*/
protected $systemManager;
/**
* The theme access checker service.
*
* @var \Drupal\Core\Theme\ThemeAccessCheck
*/
protected $themeAccess;
/**
* The form builder service.
*
* @var \Drupal\Core\Form\FormBuilderInterface
*/
protected $formBuilder;
/**
* The theme handler service.
*
* @var \Drupal\Core\Extension\ThemeHandlerInterface
*/
protected $themeHandler;
/**
* The menu link tree service.
*
* @var \Drupal\Core\Menu\MenuLinkTreeInterface
*/
protected $menuLinkTree;
/**
* Constructs a new SystemController.
*
* @param \Drupal\system\SystemManager $systemManager
* System manager service.
* @param \Drupal\Core\Entity\Query\QueryFactory $queryFactory
* The entity query object.
* @param \Drupal\Core\Theme\ThemeAccessCheck $theme_access
* The theme access checker service.
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
* The form builder.
* @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
* The theme handler.
* @param \Drupal\Core\Menu\MenuLinkTreeInterface
* The menu link tree service.
*/
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;
}
/**
* {@inheritdoc}
*/
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'));
}
/**
* Provide the administration overview page.
*
* @param string $link_id
* The ID of the administrative path link for which to display child links.
*
* @return array
* A renderable array of the administration overview page.
*/
public function overview($link_id) {
// 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' => $this
->url('system.status'),
)), 'error');
}
// Load all menu links below it.
$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));
// Only render accessible links.
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;
}
}
/**
* 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
*/
public function compactPage($mode) {
user_cookie_save(array(
'admin_compact_mode' => $mode == 'on',
));
return $this
->redirect('<front>');
}
/**
* Provides a single block from the administration menu as a page.
*/
public function systemAdminMenuBlockPage() {
return $this->systemManager
->getBlockContents();
}
/**
* Returns a theme listing.
*
* @return string
* An HTML string of the theme listing page.
*
* @todo Move into ThemeController.
*/
public function themesPage() {
$config = $this
->config('system.theme');
// Get all available themes.
$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';
// Identify theme screenshot.
$theme->screenshot = NULL;
// Create a list which includes the current theme and all its base themes.
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(),
);
}
// Look for a screenshot in the current theme or in its closest ancestor.
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)) {
// Ensure this theme is compatible with this version of core.
$theme->incompatible_core = !isset($theme->info['core']) || $theme->info['core'] != \DRUPAL::CORE_COMPATIBILITY;
// Require the 'content' region to make sure the main page
// content has a common place in all themes.
$theme->incompatible_region = !isset($theme->info['regions']['content']);
$theme->incompatible_php = version_compare(phpversion(), $theme->info['php']) < 0;
// Confirmed that the base theme is available.
$theme->incompatible_base = isset($theme->info['base theme']) && !isset($themes[$theme->info['base theme']]);
// Confirm that the theme engine is available.
$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) {
// Create the operations links.
$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;
}
// Check it isn't the base of theme of an installed theme.
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'],
)),
),
);
}
}
// Add notes to default and administration theme.
$theme->notes = array();
if ($theme->is_default) {
$theme->notes[] = $this
->t('default theme');
}
if ($theme->is_admin) {
$theme->notes[] = $this
->t('admin theme');
}
// Sort installed and uninstalled themes into their own groups.
$theme_groups[$theme->status ? 'installed' : 'uninstalled'][] = $theme;
}
// There are two possible theme groups.
$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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ControllerBase:: |
protected | property | The configuration factory. | |
ControllerBase:: |
protected | property | The current user service. | 1 |
ControllerBase:: |
protected | property | The entity form builder. | |
ControllerBase:: |
protected | property | The entity manager. | 1 |
ControllerBase:: |
protected | property | The entity type manager. | |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The language manager. | 1 |
ControllerBase:: |
protected | property | The module handler. | 2 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity manager service. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity type manager. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 3 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the language manager service. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function | Returns the state storage service. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
SystemController:: |
protected | property |
The form builder service. Overrides ControllerBase:: |
|
SystemController:: |
protected | property | The menu link tree service. | |
SystemController:: |
protected | property | The entity query factory object. | |
SystemController:: |
protected | property | System Manager Service. | |
SystemController:: |
protected | property | The theme access checker service. | |
SystemController:: |
protected | property | The theme handler service. | |
SystemController:: |
public | function | Sets whether the admin menu is in compact mode or not. | |
SystemController:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
SystemController:: |
public | function | Provide the administration overview page. | |
SystemController:: |
public | function | Provides a single block from the administration menu as a page. | |
SystemController:: |
public | function | Returns a theme listing. | |
SystemController:: |
public | function | Constructs a new SystemController. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Returns a redirect response object for the specified route. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |