function public static function Unicode::extractHook

8.x-3.x Unicode.php public static Unicode::extractHook($string, $suffix = NULL, $prefix = NULL)

Extracts the hook name from a function name.

Parameters

string $string: The function name to extract the hook name from.

string $suffix: A suffix hook ending (like "alter") to also remove.

string $prefix: A prefix hook beginning (like "form") to also remove.

Return value

string The extracted hook name.

Class

Unicode
Extends \Drupal\Component\Utility\Unicode.

Namespace

Drupal\bootstrap\Utility

Source src/Utility/Unicode.php (line 57)

public static function extractHook($string, $suffix = NULL, $prefix = NULL) {
  $regex = '^(' . implode('|', array_keys(Bootstrap::getTheme()->getAncestry())) . ')';
  $regex .= $prefix ? '_' . $prefix : '';
  $regex .= $suffix ? '_|_' . $suffix . '$' : '';
  return preg_replace("/$regex/", '', $string);
}