Documentation

FormRendererInterface

Renders a form into HTML.

Tags
author

Bernhard Schussek bschussek@gmail.com

Table of Contents

Methods

getEngine()  : FormRendererEngineInterface
Returns the engine used by this renderer.
humanize()  : string
Makes a technical name human readable.
renderBlock()  : string
Renders a named block of the form theme.
renderCsrfToken()  : string
Renders a CSRF token.
searchAndRenderBlock()  : string
Searches and renders a block for a given name suffix.
setTheme()  : mixed
Sets the theme(s) to be used for rendering a view and its children.

Methods

humanize()

Makes a technical name human readable.

public humanize(string $text) : string

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
$text : string
Return values
string

renderBlock()

Renders a named block of the form theme.

public renderBlock(FormView $view, string $blockName[, array<string|int, mixed> $variables = [] ]) : string
Parameters
$view : FormView

The view for which to render the block

$blockName : string
$variables : array<string|int, mixed> = []

The variables to pass to the template

Return values
string

renderCsrfToken()

Renders a CSRF token.

public renderCsrfToken(string $tokenId) : string

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
$tokenId : string
Return values
string

searchAndRenderBlock()

Searches and renders a block for a given name suffix.

public searchAndRenderBlock(FormView $view, string $blockNameSuffix[, array<string|int, mixed> $variables = [] ]) : string

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
$view : FormView

The view for which to render the block

$blockNameSuffix : string
$variables : array<string|int, mixed> = []

The variables to pass to the template

Return values
string

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

If true, will use default themes specified in the renderer


        
On this page

Search results