You are here

protected function Registry::completeSuggestion in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Theme/Registry.php \Drupal\Core\Theme\Registry::completeSuggestion()

Completes the definition of the requested suggestion hook.

Parameters

string $hook: The name of the suggestion hook to complete.

array $cache: The theme registry, as documented in \Drupal\Core\Theme\Registry::processExtension().

1 call to Registry::completeSuggestion()
Registry::postProcessExtension in core/lib/Drupal/Core/Theme/Registry.php
Completes the theme registry adding discovered functions and hooks.

File

core/lib/Drupal/Core/Theme/Registry.php, line 623

Class

Registry
Defines the theme registry service.

Namespace

Drupal\Core\Theme

Code

protected function completeSuggestion($hook, array &$cache) {
  $previous_hook = $hook;
  $incomplete_previous_hook = [];

  // Continue looping if the candidate hook doesn't exist or if the candidate
  // hook has incomplete preprocess functions, and if the candidate hook is a
  // suggestion (has a double underscore).
  while ((!isset($cache[$previous_hook]) || isset($cache[$previous_hook]['incomplete preprocess functions'])) && ($pos = strrpos($previous_hook, '__'))) {

    // Find the first existing candidate hook that has incomplete preprocess
    // functions.
    if (isset($cache[$previous_hook]) && !$incomplete_previous_hook && isset($cache[$previous_hook]['incomplete preprocess functions'])) {
      $incomplete_previous_hook = $cache[$previous_hook];
      unset($incomplete_previous_hook['incomplete preprocess functions']);
    }
    $previous_hook = substr($previous_hook, 0, $pos);
    $this
      ->mergePreprocessFunctions($hook, $previous_hook, $incomplete_previous_hook, $cache);
  }

  // In addition to processing suggestions, include base hooks.
  if (isset($cache[$hook]['base hook'])) {

    // In order to retain the additions from above, pass in the current hook
    // as the parent hook, otherwise it will be overwritten.
    $this
      ->mergePreprocessFunctions($hook, $cache[$hook]['base hook'], $cache[$hook], $cache);
  }
}