function Registry::getBaseHook

Same name in other branches
  1. 9 core/lib/Drupal/Core/Theme/Registry.php \Drupal\Core\Theme\Registry::getBaseHook()
  2. 8.9.x core/lib/Drupal/Core/Theme/Registry.php \Drupal\Core\Theme\Registry::getBaseHook()
  3. 10 core/lib/Drupal/Core/Theme/Registry.php \Drupal\Core\Theme\Registry::getBaseHook()

Returns the base hook for a given hook suggestion.

Parameters

string $hook: The name of a theme hook whose base hook to find.

Return value

string|false The name of the base hook or FALSE.

File

core/lib/Drupal/Core/Theme/Registry.php, line 335

Class

Registry
Defines the theme registry service.

Namespace

Drupal\Core\Theme

Code

public function getBaseHook($hook) {
    $this->init($this->themeName);
    $base_hook = $hook;
    // Iteratively strip everything after the last '__' delimiter, until a
    // base hook definition is found. Recursive base hooks of base hooks are
    // not supported, so the base hook must be an original implementation that
    // points to a template.
    while ($pos = strrpos($base_hook, '__')) {
        $base_hook = substr($base_hook, 0, $pos);
        if (isset($this->registry[$base_hook]['exists'])) {
            break;
        }
    }
    if ($pos !== FALSE && $base_hook !== $hook) {
        return $base_hook;
    }
    return FALSE;
}

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