Commit 07cd3c99 authored by catch's avatar catch

Issue #2188721 by Cottser, aspilicious: Theme suggestions don't load necessary include files.

parent f718eda9
......@@ -569,13 +569,6 @@ function _theme($hook, $variables = array()) {
// point path_to_theme() to the currently used theme path:
$theme_path = $info['theme path'];
// Include a file if the theme function or variable preprocessor is held
// elsewhere.
if (!empty($info['includes'])) {
foreach ($info['includes'] as $include_file) {
include_once DRUPAL_ROOT . '/' . $include_file;
}
}
// If a renderable array is passed as $variables, then set $variables to
// the arguments expected by the theme function.
......@@ -648,6 +641,14 @@ function _theme($hook, $variables = array()) {
}
}
// Include a file if the theme function or variable preprocessor is held
// elsewhere.
if (!empty($info['includes'])) {
foreach ($info['includes'] as $include_file) {
include_once DRUPAL_ROOT . '/' . $include_file;
}
}
// Invoke the variable preprocessors, if any.
if (isset($info['base hook'])) {
$base_hook = $info['base hook'];
......
......@@ -138,6 +138,24 @@ function testThemeFunctionSuggestionsAlter() {
$this->assertText('Theme function overridden based on new theme suggestion provided by a module.');
}
/**
* Tests that theme suggestion alter hooks work with theme hook includes.
*/
public function testSuggestionsAlterInclude() {
// Check the original theme output.
$this->drupalGet('theme-test/suggestion-alter-include');
$this->assertText('Original function before altering theme suggestions.');
// Enable theme_suggestions_test module and make two requests to make sure
// the include file is always loaded. The file will always be included for
// the first request because the theme registry is being rebuilt.
\Drupal::moduleHandler()->install(array('theme_suggestions_test'));
$this->drupalGet('theme-test/suggestion-alter-include');
$this->assertText('Function suggested via suggestion alter hook found in include file.', 'Include file loaded for initial request.');
$this->drupalGet('theme-test/suggestion-alter-include');
$this->assertText('Function suggested via suggestion alter hook found in include file.', 'Include file loaded for second request.');
}
/**
* Tests execution order of theme suggestion alter hooks.
*
......
<?php
/**
* @file
* Include file for testing theme suggestion hooks.
*/
/**
* Returns HTML for a theme function include test.
*/
function theme_theme_suggestions_test_include($variables) {
return 'Function suggested via suggestion alter hook found in include file.';
}
......@@ -5,6 +5,17 @@
* Support module for testing theme suggestions.
*/
/**
* Implements hook_theme().
*/
function theme_suggestions_test_theme() {
$items['theme_suggestions_test_include'] = array(
'file' => 'theme_suggestions_test.inc',
'variables' => array(),
);
return $items;
}
/**
* Implements hook_theme_suggestions_alter().
*/
......@@ -36,3 +47,10 @@ function theme_suggestions_test_theme_suggestions_theme_test_function_suggestion
function theme_suggestions_test_theme_suggestions_theme_test_specific_suggestions_alter(array &$suggestions, array $variables) {
$suggestions[] = 'theme_test_specific_suggestions__' . 'variant__foo';
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function theme_suggestions_test_theme_suggestions_theme_test_suggestions_include_alter(array &$suggestions, array $variables, $hook) {
$suggestions[] = 'theme_suggestions_test_include';
}
......@@ -127,4 +127,12 @@ function functionSuggestionAlter() {
return array('#theme' => 'theme_test_function_suggestions');
}
/**
* Menu callback for testing includes with suggestion alter hooks.
*/
function suggestionAlterInclude() {
return array('#theme' => 'theme_test_suggestions_include');
}
}
......@@ -33,6 +33,9 @@ function theme_test_theme($existing, $type, $theme, $path) {
$items['theme_test_function_suggestions'] = array(
'variables' => array(),
);
$items['theme_test_suggestions_include'] = array(
'variables' => array(),
);
$items['theme_test_foo'] = array(
'variables' => array('foo' => NULL),
);
......@@ -138,3 +141,10 @@ function theme_test_theme_suggestions_alter(array &$suggestions, array $variable
function theme_test_theme_suggestions_theme_test_suggestions_alter(array &$suggestions, array $variables) {
drupal_set_message(__FUNCTION__ . '() executed.');
}
/**
* Returns HTML for a theme function include test.
*/
function theme_theme_test_suggestions_include($variables) {
return 'Original function before altering theme suggestions.';
}
......@@ -92,3 +92,10 @@ function_suggestion_alter:
_content: '\Drupal\theme_test\ThemeTestController::functionSuggestionAlter'
requirements:
_access: 'TRUE'
suggestion_alter_include:
path: '/theme-test/suggestion-alter-include'
defaults:
_content: '\Drupal\theme_test\ThemeTestController::suggestionAlterInclude'
requirements:
_access: 'TRUE'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment