diff --git a/core/core.services.yml b/core/core.services.yml index 6568923..10cd1e5 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -663,7 +663,7 @@ services: feed.writer.wellformedwebrendererentry: class: Zend\Feed\Writer\Extension\WellFormedWeb\Renderer\Entry theme.initialisation: - class: Drupal\Core\Theme\Initialisation + class: Drupal\Core\Theme\Initialization arguments: ['@theme_handler', '@theme.negotiator'] calls: - [setRequest, ['@?request=']] diff --git a/core/lib/Drupal/Core/Theme/Initialization.php b/core/lib/Drupal/Core/Theme/Initialization.php index 99da43e..22ce3f9 100644 --- a/core/lib/Drupal/Core/Theme/Initialization.php +++ b/core/lib/Drupal/Core/Theme/Initialization.php @@ -11,7 +11,7 @@ use Symfony\Component\HttpFoundation\Request; /** - * Provides the theme initialisation logic. + * Provides the theme initialization logic. */ class Initialization { @@ -59,6 +59,11 @@ public function setRequest(Request $request) { $this->request = $request; } + /** + * Initializes the theme system. + * + * This method uses the theme negotiator to figure out the active theme. + */ public function initThemeSystem() { global $theme, $theme_key; @@ -84,8 +89,7 @@ public function initThemeSystem() { $ancestor = $themes[$ancestor]->base_theme; $base_theme[] = $themes[$ancestor]; } - $this->addAssets($themes[$theme], array_reverse($base_theme)); - $this->loadIncludes($themes[$theme], array_reverse($base_theme)); + $this->initThemeSystemWithLoadedInformation($themes[$theme], array_reverse($base_theme)); } /** @@ -93,7 +97,7 @@ public function initThemeSystem() { * * This function is useful to initialize a theme when no database is present. * - * @param $theme + * @param \stdClass $theme * An object with the following information: * filename * The .info.yml file for this theme. The 'path' to @@ -105,14 +109,30 @@ public function initThemeSystem() { * The primary stylesheet for the theme. (Optional) * engine * The name of theme engine to use. (Optional) - * @param $base_theme + * @param \stdClass[] $base_theme * An optional array of objects that represent the 'base theme' if the * theme is meant to be derivative of another theme. It requires * the same information as the $theme object. It should be in * 'oldest first' order, meaning the top level of the chain will * be first. */ - public function addAssets($theme, $base_theme = array()) { + public function initThemeSystemWithLoadedInformation($theme, $base_theme = array()) { + $this->addAssets($theme, $base_theme); + $this->loadIncludes($theme, $base_theme); + } + + /** + * Adds all assets onto the response. + * + * @param \stdClass $theme + * The theme object + * + * @param \stdClass[] $base_theme + * A list of theme objects of all base themes. + * + * @see \Drupal\Core\Theme\Initialization::initThemeSystemWithLoadedInformation() + */ + protected function addAssets($theme, $base_theme = array()) { global $theme_info, $base_theme_info, $theme_path; $theme_info = $theme; $base_theme_info = $base_theme; @@ -224,12 +244,17 @@ public function addAssets($theme, $base_theme = array()) { } /** + * Load the .theme file as well as the theme engine. + * * @param \stdClass $theme - * @param \stdClass $base_theme + * The theme object. + * + * @param \stdClass[] $base_theme + * A list of theme objects of all base themes. * - * @return string + * @see \Drupal\Core\Theme\Initialization::initThemeSystemWithLoadedInformation() */ - public function loadIncludes($theme, $base_theme) { + protected function loadIncludes($theme, array $base_theme = array()) { global $theme_engine; $theme_engine = NULL; @@ -263,7 +288,6 @@ public function loadIncludes($theme, $base_theme) { // Always include Twig as the default theme engine. include_once DRUPAL_ROOT . '/core/themes/engines/twig/twig.engine'; - return $theme_engine; } }