TwigRendererEngine
extends AbstractRendererEngine
in package
Default implementation of {@link FormRendererEngineInterface}.
Tags
Table of Contents
- CACHE_KEY_VAR = 'cache_key'
- The variable in {@link FormView} used as cache key.
- $defaultThemes : array<string|int, mixed>
- $resources : array<string|int, array<string|int, mixed>>
- $themes : array<string|int, array<string|int, mixed>>
- $useDefaultThemes : array<string|int, bool>
- $environment : Environment
- $resourceHierarchyLevels : array<string|int, array<string|int, int|false>>
- $template : Template
- __construct() : mixed
- Creates a new renderer engine.
- getResourceForBlockName() : mixed
- Returns the resource for a block name.
- getResourceForBlockNameHierarchy() : mixed
- Returns the resource for a block hierarchy.
- getResourceHierarchyLevel() : int|bool
- Returns the hierarchy level at which a resource can be found.
- renderBlock() : mixed
- {@inheritdoc}
- setTheme() : mixed
- Sets the theme(s) to be used for rendering a view and its children.
- loadResourceForBlockName() : bool
- Loads the cache with the resource for a given block name.
- loadResourcesFromTheme() : mixed
- Loads the resources for all blocks in a theme.
- loadResourceForBlockNameHierarchy() : bool
- Loads the cache with the resource for a specific level of a block hierarchy.
Constants
CACHE_KEY_VAR
The variable in {@link FormView} used as cache key.
public
mixed
CACHE_KEY_VAR
= 'cache_key'
Properties
$defaultThemes
protected
array<string|int, mixed>
$defaultThemes
$resources
protected
array<string|int, array<string|int, mixed>>
$resources
= []
$themes
protected
array<string|int, array<string|int, mixed>>
$themes
= []
$useDefaultThemes
protected
array<string|int, bool>
$useDefaultThemes
= []
$environment
private
Environment
$environment
$resourceHierarchyLevels
private
array<string|int, array<string|int, int|false>>
$resourceHierarchyLevels
= []
$template
private
Template
$template
Methods
__construct()
Creates a new renderer engine.
public
__construct(array<string|int, mixed> $defaultThemes, Environment $environment) : mixed
Parameters
- $defaultThemes : array<string|int, mixed>
-
The default themes. The type of these themes is open to the implementation.
- $environment : Environment
Return values
mixed —getResourceForBlockName()
Returns the resource for a block name.
public
getResourceForBlockName(FormView $view, mixed $blockName) : mixed
Parameters
- $view : FormView
-
The view for determining the used themes. First the themes attached directly to the view with are considered, then the ones of its parent etc.
- $blockName : mixed
-
The name of the block to render
Return values
mixed —the renderer resource or false, if none was found
getResourceForBlockNameHierarchy()
Returns the resource for a block hierarchy.
public
getResourceForBlockNameHierarchy(FormView $view, array<string|int, mixed> $blockNameHierarchy, mixed $hierarchyLevel) : mixed
Parameters
- $view : FormView
-
The view for determining the used themes. First the themes attached directly to the view with are considered, then the ones of its parent etc.
- $blockNameHierarchy : array<string|int, mixed>
-
The block name hierarchy, with the root block at the beginning
- $hierarchyLevel : mixed
-
The level in the hierarchy at which to start looking. Level 0 indicates the root block, i.e. the first element of $blockNameHierarchy.
Return values
mixed —The renderer resource or false, if none was found
getResourceHierarchyLevel()
Returns the hierarchy level at which a resource can be found.
public
getResourceHierarchyLevel(FormView $view, array<string|int, mixed> $blockNameHierarchy, mixed $hierarchyLevel) : int|bool
Parameters
- $view : FormView
-
The view for determining the used themes. First the themes attached directly to the view with are considered, then the ones of its parent etc.
- $blockNameHierarchy : array<string|int, mixed>
-
The block name hierarchy, with the root block at the beginning
- $hierarchyLevel : mixed
-
The level in the hierarchy at which to start looking. Level 0 indicates the root block, i.e. the first element of $blockNameHierarchy.
Return values
int|bool —The hierarchy level or false, if no resource was found
renderBlock()
{@inheritdoc}
public
renderBlock(FormView $view, mixed $resource, mixed $blockName[, array<string|int, mixed> $variables = [] ]) : mixed
Parameters
- $view : FormView
- $resource : mixed
- $blockName : mixed
- $variables : array<string|int, mixed> = []
Return values
mixed —setTheme()
Sets the theme(s) to be used for rendering a view and its children.
public
setTheme(FormView $view, mixed $themes[, mixed $useDefaultThemes = true ]) : mixed
Parameters
- $view : FormView
-
The view to assign the theme(s) to
- $themes : mixed
-
The theme(s). The type of these themes is open to the implementation.
- $useDefaultThemes : mixed = true
-
If true, will use default themes specified in the engine
Return values
mixed —loadResourceForBlockName()
Loads the cache with the resource for a given block name.
protected
loadResourceForBlockName(string $cacheKey, FormView $view, string $blockName) : bool
This implementation eagerly loads all blocks of the themes assigned to the given view and all of its ancestors views. This is necessary, because Twig receives the list of blocks later. At that point, all blocks must already be loaded, for the case that the function "block()" is used in the Twig template.
Parameters
- $cacheKey : string
-
The cache key of the form view
- $view : FormView
-
The form view for finding the applying themes
- $blockName : string
-
The name of the block to load
Tags
Return values
bool —True if the resource could be loaded, false otherwise
loadResourcesFromTheme()
Loads the resources for all blocks in a theme.
protected
loadResourcesFromTheme(string $cacheKey, mixed &$theme) : mixed
Parameters
- $cacheKey : string
-
The cache key for storing the resource
- $theme : mixed
-
The theme to load the block from. This parameter is passed by reference, because it might be necessary to initialize the theme first. Any changes made to this variable will be kept and be available upon further calls to this method using the same theme.
Return values
mixed —loadResourceForBlockNameHierarchy()
Loads the cache with the resource for a specific level of a block hierarchy.
private
loadResourceForBlockNameHierarchy(string $cacheKey, FormView $view, array<string|int, mixed> $blockNameHierarchy, int $hierarchyLevel) : bool
Parameters
- $cacheKey : string
- $view : FormView
- $blockNameHierarchy : array<string|int, mixed>
- $hierarchyLevel : int