Drupal 8  8.0.2
Registry Class Reference
Inheritance diagram for Registry:

Public Member Functions

 __construct ($root, CacheBackendInterface $cache, LockBackendInterface $lock, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, ThemeInitializationInterface $theme_initialization, $theme_name=NULL)
 
 setThemeManager (ThemeManagerInterface $theme_manager)
 
 get ()
 
 getRuntime ()
 
 getBaseHook ($hook)
 
 reset ()
 
 destruct ()
 
 getPrefixGroupedUserFunctions ()
 

Protected Member Functions

 init ($theme_name=NULL)
 
 setCache ()
 
 build ()
 
 processExtension (array &$cache, $name, $type, $theme, $path)
 
 completeSuggestion ($hook, array &$cache)
 
 postProcessExtension (array &$cache, ActiveTheme $theme)
 
 getPath ($module)
 

Protected Attributes

 $theme
 
 $lock
 
 $registry
 
 $cache
 
 $moduleHandler
 
 $runtimeRegistry
 
 $initialized = FALSE
 
 $themeName
 
 $root
 
 $themeHandler
 
 $themeManager
 

Detailed Description

Defines the theme registry service.

Todo:
Replace local $registry variables in methods with $this->registry.

Constructor & Destructor Documentation

__construct (   $root,
CacheBackendInterface  $cache,
LockBackendInterface  $lock,
ModuleHandlerInterface  $module_handler,
ThemeHandlerInterface  $theme_handler,
ThemeInitializationInterface  $theme_initialization,
  $theme_name = NULL 
)

Constructs a object.

Parameters
string$rootThe app root.
\Drupal\Core\Cache\CacheBackendInterface$cacheThe cache backend interface to use for the complete theme registry data.
\Drupal\Core\Lock\LockBackendInterface$lockThe lock backend.
\Drupal\Core\Extension\ModuleHandlerInterface$module_handlerThe module handler to use to load modules.
\Drupal\Core\Extension\ThemeHandlerInterface$theme_handlerThe theme handler.
\Drupal\Core\Theme\ThemeInitializationInterface$theme_initializationThe theme initialization.
string$theme_name(optional) The name of the theme for which to construct the registry.

References Drupal\cache(), Drupal\lock(), Drupal\moduleHandler(), and Drupal\root().

Here is the call graph for this function:

Member Function Documentation

build ( )
protected

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 Default theme implementations topic for details.

Returns
The build theme registry.
See Also
hook_theme_registry_alter()

References Drupal\cache(), Registry\getPath(), Drupal\moduleHandler(), Cache\PERMANENT, Registry\postProcessExtension(), Registry\processExtension(), and Drupal\theme().

Referenced by Registry\get().

Here is the call graph for this function:

Here is the caller graph for this function:

completeSuggestion (   $hook,
array &  $cache 
)
protected

Completes the definition of the requested suggestion hook.

Parameters
string$hookThe name of the suggestion hook to complete.
array$cacheThe theme registry, as documented in ::processExtension().

Referenced by Registry\postProcessExtension().

Here is the caller graph for this function:

destruct ( )

{Performs destruct operations.}

Implements DestructableInterface.

get ( )

Returns the complete theme registry from cache or rebuilds it.

Returns
array The complete theme registry data array.
See Also
Registry::$registry

References Registry\build(), Drupal\cache(), Registry\init(), Drupal\moduleHandler(), and Registry\setCache().

Here is the call graph for this function:

getBaseHook (   $hook)

Returns the base hook for a given hook suggestion.

Parameters
string$hookThe name of a theme hook whose base hook to find.
Returns
string|false The name of the base hook or FALSE.

References Registry\init().

Here is the call graph for this function:

getPath (   $module)
protected

Wraps drupal_get_path().

Parameters
string$moduleThe name of the item for which the path is requested.
Returns
string

Referenced by Registry\build().

Here is the caller graph for this function:

getPrefixGroupedUserFunctions ( )

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

Returns
array Functions grouped by the first prefix.

Referenced by Registry\postProcessExtension().

Here is the caller graph for this function:

getRuntime ( )

Returns the incomplete, runtime theme registry.

Returns
A shared instance of the ThemeRegistry class, provides an ArrayObject that allows it to be accessed with array syntax and isset(), and is more lightweight than the full registry.

References Registry\init(), Drupal\moduleHandler(), and Drupal\theme().

Here is the call graph for this function:

init (   $theme_name = NULL)
protected

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.

Parameters
string$theme_name(optional) The name of the theme for which to construct the registry.

References Drupal\theme().

Referenced by Registry\get(), Registry\getBaseHook(), and Registry\getRuntime().

Here is the call graph for this function:

Here is the caller graph for this function:

postProcessExtension ( array &  $cache,
ActiveTheme  $theme 
)
protected

Completes the theme registry adding discovered functions and hooks.

Parameters
array$cacheThe theme registry as documented in ::processExtension().
\Drupal\Core\Theme\ActiveTheme$themeCurrent active theme.
See Also
::processExtension()

References Registry\completeSuggestion(), ActiveTheme\getBaseThemes(), ActiveTheme\getEngine(), ActiveTheme\getName(), Registry\getPrefixGroupedUserFunctions(), and Drupal\moduleHandler().

Referenced by Registry\build().

Here is the call graph for this function:

Here is the caller graph for this function:

processExtension ( array &  $cache,
  $name,
  $type,
  $theme,
  $path 
)
protected

Process a single implementation of hook_theme().

Parameters
array$cacheThe theme registry that will eventually be cached; It is an associative array keyed by theme hooks, whose values are associative arrays describing the hook:
  • 'type': The passed-in $type.
  • 'theme path': The passed-in $path.
  • 'function': The name of the function generating output for this theme hook. Either defined explicitly in hook_theme() or, if neither 'function' nor 'template' is defined, then the default theme function name is used. The default theme function name is the theme hook prefixed by either 'theme_' for modules or '$name_' for everything else. If 'function' is defined, 'template' is not used.
  • 'template': The filename of the template generating output for this theme hook. The template is in the directory defined by the 'path' key of hook_theme() or defaults to "$path/templates".
  • 'variables': The variables for this theme hook as defined in hook_theme(). If there is more than one implementation and 'variables' is not specified in a later one, then the previous definition is kept.
  • 'render element': The renderable element for this theme hook as defined in hook_theme(). If there is more than one implementation and 'render element' is not specified in a later one, then the previous definition is kept.
  • See the Theme system overview topic for detailed documentation.
string$nameThe name of the module, theme engine, base theme engine, theme or base theme implementing hook_theme().
string$typeOne of 'module', 'theme_engine', 'base_theme_engine', 'theme', or 'base_theme'. Unlike regular hooks that can only be implemented by modules, each of these can implement hook_theme(). This function is called in aforementioned order and new entries override older ones. For example, if a theme hook is both defined by a module and a theme, then the definition in the theme will be used.
string$themeThe actual name of theme, module, etc. that is being processed.
string$pathThe directory where $name is. For example, modules/system or themes/bartik.
See Also
::render()
hook_theme()
::listInfo()
twig_render_template()
Exceptions
\BadFunctionCallException

References Drupal\moduleHandler(), and Drupal\root().

Referenced by Registry\build().

Here is the call graph for this function:

Here is the caller graph for this function:

reset ( )

Invalidates theme registry caches.

To be called when the list of enabled extensions is changed.

References Cache\invalidateTags().

Here is the call graph for this function:

setCache ( )
protected

Persists the theme registry in the cache backend.

References Drupal\cache(), Cache\PERMANENT, and Drupal\theme().

Referenced by Registry\get().

Here is the call graph for this function:

Here is the caller graph for this function:

setThemeManager ( ThemeManagerInterface  $theme_manager)

Sets the theme manager.

Parameters
\Drupal\Core\Theme\ThemeManagerInterface$theme_managerThe theme manager.

The documentation for this class was generated from the following file: