class PermalinkExtension extends Twig_Extension

Class PermalinkExtension is injected as twig.extension.permalink service. PermalinkExtension handles the logic and provides necessary data for managed entity in twig.

Methods

__construct(UrlGeneratorInterface $generator)

PermalinkExtension constructor.

array
getFunctions()

Returns a list of functions to add to the existing list.

string
getUrl(array $parameters = array(), bool $schemeRelative = false)

Generate absolute permalink route url

string
getPath(array $parameters = array(), string $entityType = 'product', bool $relative = false)

Generate permalink route path

array
isUrlGenerationSafe(Twig_Node $argsNode)

Determines at compile time whether the generated URL will be safe and thus saving the unneeded automatic escaping for performance reasons.

getName()

{@inheritdoc}

Details

at line 46
__construct(UrlGeneratorInterface $generator)

PermalinkExtension constructor.

Parameters

UrlGeneratorInterface $generator

at line 56
array getFunctions()

Returns a list of functions to add to the existing list.

Return Value

array An array of functions

at line 71
string getUrl(array $parameters = array(), bool $schemeRelative = false)

Generate absolute permalink route url

Parameters

array $parameters
bool $schemeRelative

Return Value

string

at line 86
string getPath(array $parameters = array(), string $entityType = 'product', bool $relative = false)

Generate permalink route path

Parameters

array $parameters
string $entityType
bool $relative

Return Value

string

Exceptions

InvalidArgumentException

at line 180
array isUrlGenerationSafe(Twig_Node $argsNode)

Determines at compile time whether the generated URL will be safe and thus saving the unneeded automatic escaping for performance reasons.

The URL generation process percent encodes non-alphanumeric characters. So there is no risk that malicious/invalid characters are part of the URL. The only character within an URL that must be escaped in html is the ampersand ("&") which separates query params. So we cannot mark the URL generation as always safe, but only when we are sure there won't be multiple query params. This is the case when there are none or only one constant parameter given. E.g. we know beforehand this will be safe: - path('route') - path('route', {'param': 'value'}) But the following may not: - path('route', var) - path('route', {'param': ['val1', 'val2'] }) // a sub-array - path('route', {'param1': 'value1', 'param2': 'value2'}) If param1 and param2 reference placeholder in the route, it would still be safe. But we don't know.

Parameters

Twig_Node $argsNode The arguments of the path/url function

Return Value

array An array with the contexts the URL is safe

at line 199
getName()

{@inheritdoc}