class FormRenderer implements FormRendererInterface

Renders a form into HTML using a rendering engine.

Constants

CACHE_KEY_VAR

Methods

__construct(FormRendererEngineInterface $engine, CsrfTokenManagerInterface $csrfTokenManager = null)

No description

getEngine()

Returns the engine used by this renderer.

setTheme(FormView $view, $themes)

Sets the theme(s) to be used for rendering a view and its children.

string
renderCsrfToken(string $tokenId)

Renders a CSRF token.

string
renderBlock(FormView $view, string $blockName, array $variables = [])

Renders a named block of the form theme.

string
searchAndRenderBlock(FormView $view, string $blockNameSuffix, array $variables = [])

Searches and renders a block for a given name suffix.

string
humanize(string $text)

Makes a technical name human readable.

encodeCurrency(Environment $environment, $text, $widget = '')

No description

Details

at line 34
__construct(FormRendererEngineInterface $engine, CsrfTokenManagerInterface $csrfTokenManager = null)

Parameters

FormRendererEngineInterface $engine
CsrfTokenManagerInterface $csrfTokenManager

at line 43
FormRendererEngineInterface getEngine()

Returns the engine used by this renderer.

Return Value

FormRendererEngineInterface The renderer engine

at line 51
setTheme(FormView $view, $themes)

Sets the theme(s) to be used for rendering a view and its children.

Parameters

FormView $view
$themes

at line 60
string renderCsrfToken(string $tokenId)

Renders a CSRF token.

Use this helper for CSRF protection without the overhead of creating a form.

<input type="hidden" name="token" value="<?php $renderer->renderCsrfToken('rm_user_'.$user->getId()) ?>">

Check the token in your action using the same token ID.

// $csrfProvider being an instance of Symfony\Component\Security\Csrf\TokenGenerator\TokenGeneratorInterface
if (!$csrfProvider->isCsrfTokenValid('rm_user_'.$user->getId(), $token)) {
    throw new \RuntimeException('CSRF attack detected.');
}

Parameters

string $tokenId The ID of the CSRF token

Return Value

string A CSRF token

at line 72
string renderBlock(FormView $view, string $blockName, array $variables = [])

Renders a named block of the form theme.

Parameters

FormView $view The view for which to render the block
string $blockName The name of the block
array $variables The variables to pass to the template

Return Value

string The HTML markup

at line 131
string searchAndRenderBlock(FormView $view, string $blockNameSuffix, array $variables = [])

Searches and renders a block for a given name suffix.

The block is searched by combining the block names stored in the form view with the given suffix. If a block name is found, that block is rendered.

If this method is called recursively, the block search is continued where a block was found before.

Parameters

FormView $view The view for which to render the block
string $blockNameSuffix The suffix of the block name
array $variables The variables to pass to the template

Return Value

string The HTML markup

at line 283
string humanize(string $text)

Makes a technical name human readable.

Sequences of underscores are replaced by single spaces. The first letter of the resulting string is capitalized, while all other letters are turned to lowercase.

Parameters

string $text The text to humanize

Return Value

string The humanized text

at line 291
encodeCurrency(Environment $environment, $text, $widget = '')

Parameters

Environment $environment
$text
$widget