diff --git a/core/lib/Drupal/Core/Extension/Extension.php b/core/lib/Drupal/Core/Extension/Extension.php index 0238714..da8b6e8 100644 --- a/core/lib/Drupal/Core/Extension/Extension.php +++ b/core/lib/Drupal/Core/Extension/Extension.php @@ -45,6 +45,13 @@ class Extension implements \Serializable { protected $root; /** + * The load method has completed. + * + * @var bool + */ + protected $loaded = FALSE; + + /** * Constructs a new Extension object. * * @param string $root @@ -136,8 +143,9 @@ public function getExtensionFilename() { * TRUE if this extension has a main extension file, FALSE otherwise. */ public function load() { - if ($this->filename) { + if ($this->filename && !$this->loaded) { include_once $this->root . '/' . $this->getPath() . '/' . $this->filename; + $this->loaded = TRUE; return TRUE; } return FALSE; diff --git a/core/lib/Drupal/Core/Theme/ThemeInitialization.php b/core/lib/Drupal/Core/Theme/ThemeInitialization.php index bf58584..27e52a3 100644 --- a/core/lib/Drupal/Core/Theme/ThemeInitialization.php +++ b/core/lib/Drupal/Core/Theme/ThemeInitialization.php @@ -127,11 +127,21 @@ public function getActiveThemeByName($theme_name) { * {@inheritdoc} */ public function loadActiveTheme(ActiveTheme $active_theme) { + // Load the base themes and active theme. + foreach ($active_theme->getBaseThemes() as $base) { + $base->getExtension()->load(); + // Include the theme file or the engine. + if ($base->getOwner()) { + include_once $this->root . '/' . $base->getOwner(); + } + } + $active_theme->getExtension()->load(); + // Include the active theme's owner file too. + if ($active_theme->getOwner()) { + include_once $this->root . '/' . $active_theme->getOwner(); + } // Initialize the theme. if ($theme_engine = $active_theme->getEngine()) { - // Include the engine. - include_once $this->root . '/' . $active_theme->getOwner(); - if (function_exists($theme_engine . '_init')) { foreach ($active_theme->getBaseThemes() as $base) { call_user_func($theme_engine . '_init', $base->getExtension()); @@ -139,20 +149,6 @@ public function loadActiveTheme(ActiveTheme $active_theme) { call_user_func($theme_engine . '_init', $active_theme->getExtension()); } } - else { - // include non-engine theme files - foreach ($active_theme->getBaseThemes() as $base) { - // Include the theme file or the engine. - if ($base->getOwner()) { - include_once $this->root . '/' . $base->getOwner(); - } - } - // and our theme gets one too. - if ($active_theme->getOwner()) { - include_once $this->root . '/' . $active_theme->getOwner(); - } - } - // Always include Twig as the default theme engine. include_once $this->root . '/core/themes/engines/twig/twig.engine'; } diff --git a/core/themes/engines/twig/twig.engine b/core/themes/engines/twig/twig.engine index c8f8f49..d76db36 100644 --- a/core/themes/engines/twig/twig.engine +++ b/core/themes/engines/twig/twig.engine @@ -26,16 +26,6 @@ function twig_extension() { } /** - * Includes .theme file from themes. - * - * @param \Drupal\Core\Extension\Extension $theme - * The theme extension object. - */ -function twig_init(Extension $theme) { - $theme->load(); -} - -/** * Implements hook_render_template(). * * Renders a Twig template.