function ThemeManager::getImplementationsForTheme

Gets a hook implementation list for a specific hook.

Parameters

string $theme_key: The theme machine name.

string $hook: The hook name.

Return value

array Array with hook implementations.

3 calls to ThemeManager::getImplementationsForTheme()
ThemeManager::alterForTheme in core/lib/Drupal/Core/Theme/ThemeManager.php
@todo Should we cache some of these information?
ThemeManager::invoke in core/lib/Drupal/Core/Theme/ThemeManager.php
Invokes a hook in a particular theme.
ThemeManager::invokeAllWith in core/lib/Drupal/Core/Theme/ThemeManager.php
Executes a callback for each implementation of a hook for a theme.

File

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

Class

ThemeManager
Provides the default implementation of a theme manager.

Namespace

Drupal\Core\Theme

Code

protected function getImplementationsForTheme(string $theme_key, string $hook) : array {
  if (!isset($this->allHookImplementations)) {
    if ($cache = $this->cache
      ->get('theme_hook_data')) {
      $this->allHookImplementations = $cache->data;
    }
    else {
      $this->allHookImplementations = $this->keyValueFactory
        ->get('hook_data')
        ->get('theme_hook_list') ?? [];
      $this->cache
        ->set('theme_hook_data', $this->allHookImplementations);
    }
  }
  if (!isset($this->themeHookImplementations[$theme_key][$hook])) {
    $listeners = [];
    foreach ($this->allHookImplementations[$theme_key][$hook] ?? [] as $identifier) {
      $listeners[] = $this->callableResolver
        ->getCallableFromDefinition($identifier);
    }
    $this->themeHookImplementations[$theme_key][$hook] = $listeners;
  }
  return $this->themeHookImplementations[$theme_key][$hook];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.