final class ViewHelpers (View source)

Exposes URL, localization, image, and session-backed CSRF operations to one request's views.

Methods

__construct(UrlGenerator $urlGenerator, CsrfViewHelper $csrf, TranslatorInterface $translator, LocalizationConfig $config, ImageViewHelper|null $images = null)

Binds app-scoped utilities and the current request's CSRF helper into one template API.

string
asset(string $path)

Returns a root-relative asset URL without requiring a canonical application origin.

string
string
image(ImageReference|null $reference, ImageViewOptions|null $options = null)

Renders an image reference through the optional image integration.

string
string
url(string $route, array $params = [])

Generates a URL for a named route.

string
string
localizedUrl(string $route, array $params = [], string|null $locale = null)

Generates a locale-aware URL for a named route.

string
string
csrfField(string $name = 'default')

Renders an escaped hidden field containing a token from the current session.

string
string
csrfToken(string $name = 'default')

Returns a named CSRF token from the current session.

string
string
lang(string $key, array $replacements = [], string|null $locale = null)

Translates one message with scalar replacements.

string
string
currentLocale(string $default = 'en')

Returns the active runtime locale or a configured or caller-provided fallback.

string
array
langGroup(string $group, string|null $locale = null)

Returns one complete translation group for a locale.

array
array
langAll(string|null $locale = null)

Returns every translation group for a locale.

array

Details

__construct

__construct(UrlGenerator $urlGenerator, CsrfViewHelper $csrf, TranslatorInterface $translator, LocalizationConfig $config, ImageViewHelper|null $images = null)

Binds app-scoped utilities and the current request's CSRF helper into one template API.

Parameters

UrlGenerator $urlGenerator
CsrfViewHelper $csrf
TranslatorInterface $translator
LocalizationConfig $config
ImageViewHelper|null $images

asset

string asset(string $path)

Returns a root-relative asset URL without requiring a canonical application origin.

Parameters

string $path

Return Value

string

image

string image(ImageReference|null $reference, ImageViewOptions|null $options = null)

Renders an image reference through the optional image integration.

Parameters

ImageReference|null $reference
ImageViewOptions|null $options

Return Value

string

Exceptions

LogicException

url

string url(string $route, array $params = [])

Generates a URL for a named route.

Parameters

string $route
array $params

Return Value

string

localizedUrl

string localizedUrl(string $route, array $params = [], string|null $locale = null)

Generates a locale-aware URL for a named route.

Parameters

string $route
array $params
string|null $locale

Return Value

string

csrfField

string csrfField(string $name = 'default')

Renders an escaped hidden field containing a token from the current session.

Parameters

string $name

Return Value

string

csrfToken

string csrfToken(string $name = 'default')

Returns a named CSRF token from the current session.

Parameters

string $name

Return Value

string

lang

string lang(string $key, array $replacements = [], string|null $locale = null)

Translates one message with scalar replacements.

Parameters

string $key
array $replacements
string|null $locale

Return Value

string

currentLocale

string currentLocale(string $default = 'en')

Returns the active runtime locale or a configured or caller-provided fallback.

Parameters

string $default

Return Value

string

langGroup

array langGroup(string $group, string|null $locale = null)

Returns one complete translation group for a locale.

Parameters

string $group
string|null $locale

Return Value

array

langAll

array langAll(string|null $locale = null)

Returns every translation group for a locale.

Parameters

string|null $locale

Return Value

array