TwigRendererEngine
extends AbstractRendererEngine
in package
Default implementation of {@link FormRendererEngineInterface}.
Tags
Table of Contents
Constants
- CACHE_KEY_VAR = 'cache_key'
- The variable in {@link FormView} used as cache key.
Properties
- $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 : mixed
- $resourceHierarchyLevels : array<string|int, array<string|int, int|false>>
- $template : mixed
Methods
- __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|false
- Returns the hierarchy level at which a resource can be found.
- renderBlock() : string
- {@inheritdoc}
- reset() : void
- 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
mixed
$environment
$resourceHierarchyLevels
private
array<string|int, array<string|int, int|false>>
$resourceHierarchyLevels
= []
$template
private
mixed
$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
getResourceForBlockName()
Returns the resource for a block name.
public
getResourceForBlockName(FormView $view, string $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 : string
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, int $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 : int
-
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, int $hierarchyLevel) : int|false
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 : int
-
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|falserenderBlock()
{@inheritdoc}
public
renderBlock(FormView $view, mixed $resource, string $blockName[, array<string|int, mixed> $variables = [] ]) : string
Parameters
- $view : FormView
- $resource : mixed
- $blockName : string
- $variables : array<string|int, mixed> = []
Return values
stringreset()
public
reset() : void
setTheme()
Sets the theme(s) to be used for rendering a view and its children.
public
setTheme(FormView $view, mixed $themes[, bool $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 : bool = true
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
- $view : FormView
- $blockName : string
Tags
Return values
boolloadResourcesFromTheme()
Loads the resources for all blocks in a theme.
protected
loadResourcesFromTheme(string $cacheKey, mixed &$theme) : mixed
Parameters
- $cacheKey : string
- $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.
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