You are here

public function Registry::getPrefixGroupedUserFunctions in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Theme/Registry.php \Drupal\Core\Theme\Registry::getPrefixGroupedUserFunctions()

Gets all user functions grouped by the word before the first underscore.

Parameters

$prefixes: An array of function prefixes by which the list can be limited.

Return value

array Functions grouped by the first prefix.

1 call to Registry::getPrefixGroupedUserFunctions()
Registry::postProcessExtension in core/lib/Drupal/Core/Theme/Registry.php
Completes the theme registry adding discovered functions and hooks.

File

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

Class

Registry
Defines the theme registry service.

Namespace

Drupal\Core\Theme

Code

public function getPrefixGroupedUserFunctions($prefixes = []) {
  $functions = get_defined_functions();

  // If a list of prefixes is supplied, trim down the list to those items
  // only as efficiently as possible.
  if ($prefixes) {
    $theme_functions = preg_grep('/^(' . implode(')|(', $prefixes) . ')_/', $functions['user']);
  }
  else {
    $theme_functions = $functions['user'];
  }
  $grouped_functions = [];

  // Splitting user defined functions into groups by the first prefix.
  foreach ($theme_functions as $function) {
    list($first_prefix, ) = explode('_', $function, 2);
    $grouped_functions[$first_prefix][] = $function;
  }
  return $grouped_functions;
}