public function 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);
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Theme!ThemeManager.php/function/ThemeManager::alterForTheme/8.1.x