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.

File

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

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.