Registry
class Registry implements DestructableInterface (View source)
| internal | Theme registry is expected to be used only internally since every hook_theme() implementation depends on the way this class is built. This class may get new features in minor releases so this class should be considered internal. |
Defines the theme registry service.
Properties
| protected ActiveTheme | $theme | The theme object representing the active theme for this registry. |
|
| protected LockBackendInterface | $lock | The lock backend that should be used. |
|
| protected array | $registry | The complete theme registry. |
|
| protected CacheBackendInterface | $cache | The cache backend to use for the complete theme registry data. |
|
| protected ModuleHandlerInterface | $moduleHandler | The module handler to use to load modules. |
|
| protected ThemeRegistry[] | $runtimeRegistry | An array of incomplete, runtime theme registries, keyed by theme name. |
|
| protected bool | $initialized | Stores whether the registry was already initialized. |
|
| protected string|null | $themeName | The name of the theme for which to construct the registry, if given. |
|
| protected string | $root | The app root. |
|
| protected ThemeHandlerInterface | $themeHandler | The theme handler. |
|
| protected ThemeInitializationInterface | $themeInitialization | The theme initialization. |
|
| protected ThemeManagerInterface | $themeManager | The theme manager. |
|
| protected CacheBackendInterface | $runtimeCache | The runtime cache. |
|
| protected ModuleExtensionList | $moduleList | The module list. |
Methods
Constructs a \Drupal\Core\Theme\Registry object.
Initializes a theme with a certain name.
Returns the complete theme registry from cache or rebuilds it.
Returns the incomplete, runtime theme registry.
Persists the theme registry in the cache backend.
Returns the base hook for a given hook suggestion.
Builds the theme registry cache.
Process a single implementation of hook_theme().
Completes the definition of the requested suggestion hook.
Merges the source hook's preprocess functions into the destination hook's.
Completes the theme registry adding discovered functions and hooks.
Invalidates theme registry caches.
Performs destruct operations.
Gets all user functions grouped by the word before the first underscore.
Details
__construct(string $root, CacheBackendInterface $cache, LockBackendInterface $lock, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, ThemeInitializationInterface $theme_initialization, string $theme_name = NULL, CacheBackendInterface $runtime_cache = NULL, ModuleExtensionList $module_list = NULL)
Constructs a \Drupal\Core\Theme\Registry object.
setThemeManager(ThemeManagerInterface $theme_manager)
Sets the theme manager.
protected
init(string $theme_name = NULL)
Initializes a theme with a certain name.
This function does to much magic, so it should be replaced by another services which holds the current active theme information.
array
get()
Returns the complete theme registry from cache or rebuilds it.
ThemeRegistry
getRuntime()
Returns the incomplete, runtime theme registry.
protected
setCache()
Persists the theme registry in the cache backend.
string|false
getBaseHook(string $hook)
Returns the base hook for a given hook suggestion.
protected ThemeRegistry
build()
Builds the theme registry cache.
Theme hook definitions are collected in the following order:
- Modules
- Base theme engines
- Base themes
- Theme engine
- Theme
All theme hook definitions are essentially just collated and merged in the above order. However, various extension-specific default values and customizations are required; e.g., to record the effective file path for theme template. Therefore, this method first collects all extensions per type, and then dispatches the processing for each extension to processExtension().
After completing the collection, modules are allowed to alter it. Lastly, any derived and incomplete theme hook definitions that are hook suggestions for base hooks (e.g., 'block__node' for the base hook 'block') need to be determined based on the full registry and classified as 'base hook'.
See the @link themeable Default theme implementations topic @endlink for details.
protected
processExtension(array $cache, string $name, string $type, string $theme, string $path)
Process a single implementation of hook_theme().
protected
completeSuggestion(string $hook, array $cache)
Completes the definition of the requested suggestion hook.
protected
mergePreprocessFunctions(string $destination_hook_name, string $source_hook_name, array $parent_hook, array $cache)
Merges the source hook's preprocess functions into the destination hook's.
protected
postProcessExtension(array $cache, ActiveTheme $theme)
Completes the theme registry adding discovered functions and hooks.
reset()
Invalidates theme registry caches.
To be called when the list of enabled extensions is changed.
destruct()
Performs destruct operations.
array
getPrefixGroupedUserFunctions($prefixes = [])
Gets all user functions grouped by the word before the first underscore.
protected string
getPath(string $module)
deprecated
deprecated
Wraps drupal_get_path().