Commit 3a27db99 authored by webchick's avatar webchick

Issue #2232649 by msonnabaum: _theme micro-optimization.

parent 6edcdee3
......@@ -390,10 +390,13 @@ function list_themes($refresh = FALSE) {
*/
function _theme($hook, $variables = array()) {
static $default_attributes;
$module_handler = \Drupal::moduleHandler();
// If called before all modules are loaded, we do not necessarily have a full
// theme registry to work with, and therefore cannot process the theme
// request properly. See also \Drupal\Core\Theme\Registry::get().
if (!\Drupal::moduleHandler()->isLoaded() && !defined('MAINTENANCE_MODE')) {
if (!$module_handler->isLoaded() && !defined('MAINTENANCE_MODE')) {
throw new Exception(t('_theme() may not be called until all modules are loaded.'));
}
......@@ -488,7 +491,7 @@ function _theme($hook, $variables = array()) {
}
// Invoke hook_theme_suggestions_HOOK().
$suggestions = Drupal::moduleHandler()->invokeAll('theme_suggestions_' . $base_theme_hook, array($variables));
$suggestions = $module_handler->invokeAll('theme_suggestions_' . $base_theme_hook, array($variables));
// If _theme() was invoked with a direct theme suggestion like
// '#theme' => 'node__article', add it to the suggestions array before
// invoking suggestion alter hooks.
......@@ -502,7 +505,7 @@ function _theme($hook, $variables = array()) {
'theme_suggestions',
'theme_suggestions_' . $base_theme_hook,
);
\Drupal::moduleHandler()->alter($hooks, $suggestions, $variables, $base_theme_hook);
$module_handler->alter($hooks, $suggestions, $variables, $base_theme_hook);
// Check if each suggestion exists in the theme registry, and if so,
// use it instead of the hook that _theme() was called with. For example, a
......
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