class FormExtension extends AbstractExtension implements InitRuntimeInterface

FormExtension extends Twig with form capabilities.

Properties

TwigRendererInterface $renderer This property is public so that it can be accessed directly from compiled templates without having to call a getter, which slightly decreases performance.

Methods

__construct(TwigRendererInterface $renderer)

No description

initRuntime(Environment $environment)

{@inheritdoc}

getTokenParsers()

{@inheritdoc}

getFunctions()

{@inheritdoc}

getFilters()

{@inheritdoc}

getTests()

{@inheritdoc}

string
renderCsrfToken(string $intention)

Renders a CSRF token.

string
humanize(string $text)

Makes a technical name human readable.

bool
isSelectedChoice(ChoiceView $choice, string|array $selectedValue)

Returns whether a choice is selected for a given form value.

isRootForm(FormView $formView)

No description

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

No description

getName()

{@inheritdoc}

Details

at line 41
__construct(TwigRendererInterface $renderer)

Parameters

TwigRendererInterface $renderer

at line 49
initRuntime(Environment $environment)

{@inheritdoc}

Parameters

Environment $environment

at line 57
getTokenParsers()

{@inheritdoc}

at line 68
getFunctions()

{@inheritdoc}

at line 87
getFilters()

{@inheritdoc}

at line 98
getTests()

{@inheritdoc}

at line 113
string renderCsrfToken(string $intention)

Renders a CSRF token.

Parameters

string $intention The intention of the protected action

Return Value

string A CSRF token

at line 125
string humanize(string $text)

Makes a technical name human readable.

Parameters

string $text The text to humanize

Return Value

string The humanized text

at line 153
bool isSelectedChoice(ChoiceView $choice, string|array $selectedValue)

Returns whether a choice is selected for a given form value.

Unfortunately Twig does not support an efficient way to execute the "is_selected" closure passed to the template by ChoiceType. It is faster to implement the logic here (around 65ms for a specific form).

Directly implementing the logic here is also faster than doing so in ChoiceView (around 30ms).

The worst option tested so far is to implement the logic in ChoiceView and access the ChoiceView method directly in the template. Doing so is around 220ms slower than doing the method call here in the filter. Twig seems to be much more efficient at executing filters than at executing methods of an object.

Parameters

ChoiceView $choice The choice to check
string|array $selectedValue The selected value to compare

Return Value

bool Whether the choice is selected

See also

ChoiceView::isSelected()

at line 165
isRootForm(FormView $formView)

Parameters

FormView $formView

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

Parameters

Environment $environment
$text
$widget

at line 189
getName()

{@inheritdoc}