Chris@0: systemManager = $systemManager;
Chris@0: $this->themeAccess = $theme_access;
Chris@0: $this->formBuilder = $form_builder;
Chris@0: $this->themeHandler = $theme_handler;
Chris@0: $this->menuLinkTree = $menu_link_tree;
Chris@0: }
Chris@0:
Chris@0: /**
Chris@0: * {@inheritdoc}
Chris@0: */
Chris@0: public static function create(ContainerInterface $container) {
Chris@0: return new static(
Chris@0: $container->get('system.manager'),
Chris@0: $container->get('access_check.theme'),
Chris@0: $container->get('form_builder'),
Chris@0: $container->get('theme_handler'),
Chris@0: $container->get('menu.link_tree')
Chris@0: );
Chris@0: }
Chris@0:
Chris@0: /**
Chris@0: * Provide the administration overview page.
Chris@0: *
Chris@0: * @param string $link_id
Chris@0: * The ID of the administrative path link for which to display child links.
Chris@0: *
Chris@0: * @return array
Chris@0: * A renderable array of the administration overview page.
Chris@0: */
Chris@0: public function overview($link_id) {
Chris@0: // Check for status report errors.
Chris@0: if ($this->systemManager->checkRequirements() && $this->currentUser()->hasPermission('administer site configuration')) {
Chris@17: $this->messenger()->addError($this->t('One or more problems were detected with your Drupal installation. Check the status report for more information.', [':status' => $this->url('system.status')]));
Chris@0: }
Chris@0: // Load all menu links below it.
Chris@0: $parameters = new MenuTreeParameters();
Chris@0: $parameters->setRoot($link_id)->excludeRoot()->setTopLevelOnly()->onlyEnabledLinks();
Chris@0: $tree = $this->menuLinkTree->load(NULL, $parameters);
Chris@0: $manipulators = [
Chris@0: ['callable' => 'menu.default_tree_manipulators:checkAccess'],
Chris@0: ['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
Chris@0: ];
Chris@0: $tree = $this->menuLinkTree->transform($tree, $manipulators);
Chris@0: $tree_access_cacheability = new CacheableMetadata();
Chris@0: $blocks = [];
Chris@0: foreach ($tree as $key => $element) {
Chris@0: $tree_access_cacheability = $tree_access_cacheability->merge(CacheableMetadata::createFromObject($element->access));
Chris@0:
Chris@0: // Only render accessible links.
Chris@0: if (!$element->access->isAllowed()) {
Chris@0: continue;
Chris@0: }
Chris@0:
Chris@0: $link = $element->link;
Chris@0: $block['title'] = $link->getTitle();
Chris@0: $block['description'] = $link->getDescription();
Chris@0: $block['content'] = [
Chris@0: '#theme' => 'admin_block_content',
Chris@0: '#content' => $this->systemManager->getAdminBlock($link),
Chris@0: ];
Chris@0:
Chris@0: if (!empty($block['content']['#content'])) {
Chris@0: $blocks[$key] = $block;
Chris@0: }
Chris@0: }
Chris@0:
Chris@0: if ($blocks) {
Chris@0: ksort($blocks);
Chris@0: $build = [
Chris@0: '#theme' => 'admin_page',
Chris@0: '#blocks' => $blocks,
Chris@0: ];
Chris@0: $tree_access_cacheability->applyTo($build);
Chris@0: return $build;
Chris@0: }
Chris@0: else {
Chris@0: $build = [
Chris@0: '#markup' => $this->t('You do not have any administrative items.'),
Chris@0: ];
Chris@0: $tree_access_cacheability->applyTo($build);
Chris@0: return $build;
Chris@0: }
Chris@0: }
Chris@0:
Chris@0: /**
Chris@0: * Sets whether the admin menu is in compact mode or not.
Chris@0: *
Chris@0: * @param string $mode
Chris@0: * Valid values are 'on' and 'off'.
Chris@0: *
Chris@0: * @return \Symfony\Component\HttpFoundation\RedirectResponse
Chris@0: */
Chris@0: public function compactPage($mode) {
Chris@0: user_cookie_save(['admin_compact_mode' => ($mode == 'on')]);
Chris@0: return $this->redirect('');
Chris@0: }
Chris@0:
Chris@0: /**
Chris@0: * Provides a single block from the administration menu as a page.
Chris@0: */
Chris@0: public function systemAdminMenuBlockPage() {
Chris@0: return $this->systemManager->getBlockContents();
Chris@0: }
Chris@0:
Chris@0: /**
Chris@0: * Returns a theme listing.
Chris@0: *
Chris@0: * @return string
Chris@0: * An HTML string of the theme listing page.
Chris@0: *
Chris@0: * @todo Move into ThemeController.
Chris@0: */
Chris@0: public function themesPage() {
Chris@0: $config = $this->config('system.theme');
Chris@0: // Get all available themes.
Chris@0: $themes = $this->themeHandler->rebuildThemeData();
Chris@0: uasort($themes, 'system_sort_modules_by_info_name');
Chris@0:
Chris@0: $theme_default = $config->get('default');
Chris@17: $theme_groups = ['installed' => [], 'uninstalled' => []];
Chris@0: $admin_theme = $config->get('admin');
Chris@0: $admin_theme_options = [];
Chris@0:
Chris@0: foreach ($themes as &$theme) {
Chris@0: if (!empty($theme->info['hidden'])) {
Chris@0: continue;
Chris@0: }
Chris@0: $theme->is_default = ($theme->getName() == $theme_default);
Chris@0: $theme->is_admin = ($theme->getName() == $admin_theme || ($theme->is_default && $admin_theme == '0'));
Chris@0:
Chris@0: // Identify theme screenshot.
Chris@0: $theme->screenshot = NULL;
Chris@0: // Create a list which includes the current theme and all its base themes.
Chris@0: if (isset($themes[$theme->getName()]->base_themes)) {
Chris@0: $theme_keys = array_keys($themes[$theme->getName()]->base_themes);
Chris@0: $theme_keys[] = $theme->getName();
Chris@0: }
Chris@0: else {
Chris@0: $theme_keys = [$theme->getName()];
Chris@0: }
Chris@0: // Look for a screenshot in the current theme or in its closest ancestor.
Chris@0: foreach (array_reverse($theme_keys) as $theme_key) {
Chris@0: if (isset($themes[$theme_key]) && file_exists($themes[$theme_key]->info['screenshot'])) {
Chris@0: $theme->screenshot = [
Chris@0: 'uri' => $themes[$theme_key]->info['screenshot'],
Chris@0: 'alt' => $this->t('Screenshot for @theme theme', ['@theme' => $theme->info['name']]),
Chris@0: 'title' => $this->t('Screenshot for @theme theme', ['@theme' => $theme->info['name']]),
Chris@0: 'attributes' => ['class' => ['screenshot']],
Chris@0: ];
Chris@0: break;
Chris@0: }
Chris@0: }
Chris@0:
Chris@0: if (empty($theme->status)) {
Chris@0: // Ensure this theme is compatible with this version of core.
Chris@0: $theme->incompatible_core = !isset($theme->info['core']) || ($theme->info['core'] != \DRUPAL::CORE_COMPATIBILITY);
Chris@0: // Require the 'content' region to make sure the main page
Chris@0: // content has a common place in all themes.
Chris@0: $theme->incompatible_region = !isset($theme->info['regions']['content']);
Chris@0: $theme->incompatible_php = version_compare(phpversion(), $theme->info['php']) < 0;
Chris@0: // Confirm that all base themes are available.
Chris@0: $theme->incompatible_base = (isset($theme->info['base theme']) && !($theme->base_themes === array_filter($theme->base_themes)));
Chris@0: // Confirm that the theme engine is available.
Chris@0: $theme->incompatible_engine = isset($theme->info['engine']) && !isset($theme->owner);
Chris@0: }
Chris@0: $theme->operations = [];
Chris@0: if (!empty($theme->status) || !$theme->incompatible_core && !$theme->incompatible_php && !$theme->incompatible_base && !$theme->incompatible_engine) {
Chris@0: // Create the operations links.
Chris@0: $query['theme'] = $theme->getName();
Chris@0: if ($this->themeAccess->checkAccess($theme->getName())) {
Chris@0: $theme->operations[] = [
Chris@0: 'title' => $this->t('Settings'),
Chris@0: 'url' => Url::fromRoute('system.theme_settings_theme', ['theme' => $theme->getName()]),
Chris@0: 'attributes' => ['title' => $this->t('Settings for @theme theme', ['@theme' => $theme->info['name']])],
Chris@0: ];
Chris@0: }
Chris@0: if (!empty($theme->status)) {
Chris@0: if (!$theme->is_default) {
Chris@0: $theme_uninstallable = TRUE;
Chris@0: if ($theme->getName() == $admin_theme) {
Chris@0: $theme_uninstallable = FALSE;
Chris@0: }
Chris@0: // Check it isn't the base of theme of an installed theme.
Chris@0: foreach ($theme->required_by as $themename => $dependency) {
Chris@0: if (!empty($themes[$themename]->status)) {
Chris@0: $theme_uninstallable = FALSE;
Chris@0: }
Chris@0: }
Chris@0: if ($theme_uninstallable) {
Chris@0: $theme->operations[] = [
Chris@0: 'title' => $this->t('Uninstall'),
Chris@0: 'url' => Url::fromRoute('system.theme_uninstall'),
Chris@0: 'query' => $query,
Chris@0: 'attributes' => ['title' => $this->t('Uninstall @theme theme', ['@theme' => $theme->info['name']])],
Chris@0: ];
Chris@0: }
Chris@0: $theme->operations[] = [
Chris@0: 'title' => $this->t('Set as default'),
Chris@0: 'url' => Url::fromRoute('system.theme_set_default'),
Chris@0: 'query' => $query,
Chris@0: 'attributes' => ['title' => $this->t('Set @theme as default theme', ['@theme' => $theme->info['name']])],
Chris@0: ];
Chris@0: }
Chris@0: $admin_theme_options[$theme->getName()] = $theme->info['name'];
Chris@0: }
Chris@0: else {
Chris@0: $theme->operations[] = [
Chris@0: 'title' => $this->t('Install'),
Chris@0: 'url' => Url::fromRoute('system.theme_install'),
Chris@0: 'query' => $query,
Chris@0: 'attributes' => ['title' => $this->t('Install @theme theme', ['@theme' => $theme->info['name']])],
Chris@0: ];
Chris@0: $theme->operations[] = [
Chris@0: 'title' => $this->t('Install and set as default'),
Chris@0: 'url' => Url::fromRoute('system.theme_set_default'),
Chris@0: 'query' => $query,
Chris@0: 'attributes' => ['title' => $this->t('Install @theme as default theme', ['@theme' => $theme->info['name']])],
Chris@0: ];
Chris@0: }
Chris@0: }
Chris@0:
Chris@0: // Add notes to default and administration theme.
Chris@0: $theme->notes = [];
Chris@0: if ($theme->is_default) {
Chris@0: $theme->notes[] = $this->t('default theme');
Chris@0: }
Chris@0: if ($theme->is_admin) {
Chris@0: $theme->notes[] = $this->t('administration theme');
Chris@0: }
Chris@0:
Chris@0: // Sort installed and uninstalled themes into their own groups.
Chris@0: $theme_groups[$theme->status ? 'installed' : 'uninstalled'][] = $theme;
Chris@0: }
Chris@0:
Chris@0: // There are two possible theme groups.
Chris@0: $theme_group_titles = [
Chris@0: 'installed' => $this->formatPlural(count($theme_groups['installed']), 'Installed theme', 'Installed themes'),
Chris@0: ];
Chris@0: if (!empty($theme_groups['uninstalled'])) {
Chris@0: $theme_group_titles['uninstalled'] = $this->formatPlural(count($theme_groups['uninstalled']), 'Uninstalled theme', 'Uninstalled themes');
Chris@0: }
Chris@0:
Chris@0: uasort($theme_groups['installed'], 'system_sort_themes');
Chris@0: $this->moduleHandler()->alter('system_themes_page', $theme_groups);
Chris@0:
Chris@0: $build = [];
Chris@0: $build[] = [
Chris@0: '#theme' => 'system_themes_page',
Chris@0: '#theme_groups' => $theme_groups,
Chris@0: '#theme_group_titles' => $theme_group_titles,
Chris@0: ];
Chris@0: $build[] = $this->formBuilder->getForm('Drupal\system\Form\ThemeAdminForm', $admin_theme_options);
Chris@0:
Chris@0: return $build;
Chris@0: }
Chris@0:
Chris@0: }