getThemeIdFromThemeDetailsProviders(); if (empty($themeId)) { $themeId = $this->getCurrentThemeId(); } return $this->getThemeById($themeId); } /** * @inheritdoc */ public function setTheme(Theme $theme, $protectAlreadyExistingThemes = true) { $this->addTheme($theme, $protectAlreadyExistingThemes); $this->setCurrentTheme($theme->getId()); } /** * @inheritdoc */ public function hasTheme($themeId) { $themes = $this->getAllThemes(); if (array_key_exists($themeId, $themes)) { return true; } foreach ($themes as $currentTheme) { if ($currentTheme->getId() === $themeId) { return true; } } return false; } /** * @inheritdoc */ public function getThemeById($themeId) { $themes = $this->getAllThemes(); if (array_key_exists($themeId, $themes)) { return $themes[$themeId]; } foreach ($themes as $currentTheme) { if ($currentTheme->getId() === $themeId) { return $currentTheme; } } throw new \common_exception_InconsistentData('The requested theme does not exist. (' . $themeId . ')'); } /** * Returns the theme id provided by the themeDetailsProviders. * * @return string */ protected function getThemeIdFromThemeDetailsProviders() { $providers = $this->getThemeDetailsProviders(); foreach ($providers as $provider) { if ($provider instanceof ThemeDetailsProviderInterface) { $themeId = $provider->getThemeId(); if (!empty($themeId) && $themeId !== ' ') { if ($this->hasTheme($themeId)) { return $themeId; } \common_Logger::i( 'The requested theme ' . $themeId . ' requested by the ' . get_class($provider) . ' provider does not exist!' ); } } } return ''; } /** * Returns the unique identifier. * * @param Theme $theme * * @return string */ protected function getUniqueId(Theme $theme) { $baseId = $theme->getId(); $idNumber = 0; while ($this->hasTheme($baseId . $idNumber)) { $idNumber++; } return $baseId . $idNumber; } /** * Tells if the page has to be headless: without header and footer. * * @return bool|mixed */ public function isHeadless() { if ($this->hasOption(self::OPTION_HEADLESS_PAGE)) { return $this->getOption(self::OPTION_HEADLESS_PAGE); } $isHeadless = $this->getIsHeadLessFromThemeDetailsProviders(); if (empty($isHeadless)) { $isHeadless = false; } return $isHeadless; } /** * Returns the isHeadless details provided by the themeDetailsProviders. * * @return bool|mixed */ protected function getIsHeadlessFromThemeDetailsProviders() { $providers = $this->getThemeDetailsProviders(); foreach ($providers as $provider) { if ($provider instanceof ThemeDetailsProviderInterface) { $isHeadless = $provider->isHeadless(); if (!empty($isHeadless)) { return $isHeadless; } } } return false; } /** * Returns the theme details providers. * * @todo: think about this concept, because this could be a service. * * @return array */ protected function getThemeDetailsProviders() { if ($this->hasOption(static::OPTION_THEME_DETAILS_PROVIDERS)) { return (array)$this->getOption(static::OPTION_THEME_DETAILS_PROVIDERS); } return []; } }