function ThemeManager::invokeAllWith

Executes a callback for each implementation of a hook for a theme.

It will detect the currently active theme and invoke the given hook for the active theme and all of its base themes in reverse order.

The callback is passed two arguments, a closure which executes a hook implementation and the machine name of the current theme. Note that this is executed for just a single theme and its base themes.

Parameters

string $hook: The name of the hook to invoke.

callable(callable, string): mixed $callback: A callable that invokes a hook implementation. Such that $callback is callable(callable, string): mixed. Arguments:

  • Closure to a hook implementation.
  • Implementation theme machine name.

Overrides ThemeManagerInterface::invokeAllWith

File

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

Class

ThemeManager
Provides the default implementation of a theme manager.

Namespace

Drupal\Core\Theme

Code

public function invokeAllWith(string $hook, callable $callback) : void {
  $active_theme = $this->getActiveTheme();
  $theme_keys = $this->getThemeChain($active_theme);
  foreach ($theme_keys as $theme_key) {
    $listeners = $this->getImplementationsForTheme($theme_key, $hook);
    foreach ($listeners as $listener) {
      $callback($listener, $theme_key);
    }
  }
}

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