ThemeManager::alterForTheme

public ThemeManager::alterForTheme(ActiveTheme $theme, $type, &$data, &$context1 = NULL, &$context2 = NULL)

@todo Should we cache some of these information?

Overrides ThemeManagerInterface::alterForTheme

File

core/lib/Drupal/Core/Theme/ThemeManager.php, line 414

Class

ThemeManager
Provides the default implementation of a theme manager.

Namespace

Drupal\Core\Theme

Code

public function alterForTheme(ActiveTheme $theme, $type, &$data, &$context1 = NULL, &$context2 = NULL) {
  // Most of the time, $type is passed as a string, so for performance,
  // normalize it to that. When passed as an array, usually the first item in
  // the array is a generic type, and additional items in the array are more
  // specific variants of it, as in the case of array('form', 'form_FORM_ID').
  if (is_array($type)) {
    $extra_types = $type;
    $type = array_shift($extra_types);
    // Allow if statements in this function to use the faster isset() rather
    // than !empty() both when $type is passed as a string, or as an array with
    // one item.
    if (empty($extra_types)) {
      unset($extra_types);
    }
  }

  $theme_keys = array();
  foreach ($theme->getBaseThemes() as $base) {
    $theme_keys[] = $base->getName();
  }

  $theme_keys[] = $theme->getName();
  $functions = array();
  foreach ($theme_keys as $theme_key) {
    $function = $theme_key . '_' . $type . '_alter';
    if (function_exists($function)) {
      $functions[] = $function;
    }
    if (isset($extra_types)) {
      foreach ($extra_types as $extra_type) {
        $function = $theme_key . '_' . $extra_type . '_alter';
        if (function_exists($function)) {
          $functions[] = $function;
        }
      }
    }
  }

  foreach ($functions as $function) {
    $function($data, $context1, $context2);
  }
}
doc_Drupal
2016-10-29 09:48:14
Comments
Leave a Comment

Please login to continue.