Chris@0: root = $root; Chris@0: $this->configFactory = $config_factory; Chris@18: $this->themeList = $theme_list; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getDefault() { Chris@0: return $this->configFactory->get('system.theme')->get('default'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setDefault($name) { Chris@0: $list = $this->listInfo(); Chris@0: if (!isset($list[$name])) { Chris@17: throw new UninstalledExtensionException("$name theme is not installed."); Chris@0: } Chris@0: $this->configFactory->getEditable('system.theme') Chris@0: ->set('default', $name) Chris@0: ->save(); Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function install(array $theme_list, $install_dependencies = TRUE) { Chris@0: // We keep the old install() method as BC layer but redirect directly to the Chris@0: // theme installer. Chris@0: return \Drupal::service('theme_installer')->install($theme_list, $install_dependencies); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function uninstall(array $theme_list) { Chris@0: // We keep the old uninstall() method as BC layer but redirect directly to Chris@0: // the theme installer. Chris@0: \Drupal::service('theme_installer')->uninstall($theme_list); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function listInfo() { Chris@0: if (!isset($this->list)) { Chris@0: $this->list = []; Chris@18: $installed_themes = $this->configFactory->get('core.extension')->get('theme'); Chris@18: if (!empty($installed_themes)) { Chris@18: $installed_themes = array_intersect_key($this->themeList->getList(), $installed_themes); Chris@18: array_map([$this, 'addTheme'], $installed_themes); Chris@0: } Chris@0: } Chris@0: return $this->list; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function addTheme(Extension $theme) { Chris@18: // Register the namespaces of installed themes. Chris@18: // @todo Implement proper theme registration Chris@18: // https://www.drupal.org/project/drupal/issues/2941757 Chris@18: \Drupal::service('class_loader')->addPsr4('Drupal\\' . $theme->getName() . '\\', $this->root . '/' . $theme->getPath() . '/src'); Chris@18: Chris@0: if (!empty($theme->info['libraries'])) { Chris@0: foreach ($theme->info['libraries'] as $library => $name) { Chris@0: $theme->libraries[$library] = $name; Chris@0: } Chris@0: } Chris@0: if (isset($theme->info['engine'])) { Chris@0: $theme->engine = $theme->info['engine']; Chris@0: } Chris@0: if (isset($theme->info['base theme'])) { Chris@0: $theme->base_theme = $theme->info['base theme']; Chris@0: } Chris@0: $this->list[$theme->getName()] = $theme; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function refreshInfo() { Chris@18: $installed = $this->configFactory->get('core.extension')->get('theme'); Chris@0: // Only refresh the info if a theme has been installed. Modules are Chris@0: // installed before themes by the installer and this method is called during Chris@0: // module installation. Chris@0: if (empty($installed) && empty($this->list)) { Chris@0: return; Chris@0: } Chris@0: $this->reset(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function reset() { Chris@18: $this->themeList->reset(); Chris@0: $this->list = NULL; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function rebuildThemeData() { Chris@18: return $this->themeList->reset()->getList(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getBaseThemes(array $themes, $theme) { Chris@18: return $this->themeList->getBaseThemes($themes, $theme); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getName($theme) { Chris@18: return $this->themeList->getName($theme); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getThemeDirectories() { Chris@0: $dirs = []; Chris@0: foreach ($this->listInfo() as $name => $theme) { Chris@0: $dirs[$name] = $this->root . '/' . $theme->getPath(); Chris@0: } Chris@0: return $dirs; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function themeExists($theme) { Chris@0: $themes = $this->listInfo(); Chris@0: return isset($themes[$theme]); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getTheme($name) { Chris@0: $themes = $this->listInfo(); Chris@0: if (isset($themes[$name])) { Chris@0: return $themes[$name]; Chris@0: } Chris@17: throw new UnknownExtensionException(sprintf('The theme %s does not exist.', $name)); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function hasUi($name) { Chris@0: $themes = $this->listInfo(); Chris@0: if (isset($themes[$name])) { Chris@0: if (!empty($themes[$name]->info['hidden'])) { Chris@0: $theme_config = $this->configFactory->get('system.theme'); Chris@0: return $name == $theme_config->get('default') || $name == $theme_config->get('admin'); Chris@0: } Chris@0: return TRUE; Chris@0: } Chris@0: return FALSE; Chris@0: } Chris@0: Chris@0: }