class IfHasRoleViewHelper extends AbstractConditionViewHelper (View source)

This view helper implements an ifHasRole/else condition.

= Examples =

This is being shown in case you have the Administrator role (aka role) defined in the current package according to the controllerContext ``` This is being shown in case you have the Acme.MyPackage:Administrator role (aka role). ``` This is being shown in case you have the Acme.MyPackage:Administrator role (aka role). ``` Everything inside the tag is being displayed if you have the given role. This is being shown in case you have the role. This is being displayed in case you do not have the role. ``` Everything inside the "then" tag is displayed if you have the role. Otherwise, everything inside the "else"-tag is displayed. This is being shown in case you have the specified role ``` This is being shown in case "otherAccount" has the Acme.MyPackage:Administrator role (aka role). ```

Properties

protected ControllerContext $controllerContext

Controller Context to use

from  AbstractViewHelper
protected ObjectManagerInterface $objectManager from  AbstractViewHelper
protected LoggerInterface $logger from  AbstractViewHelper
protected bool $escapeOutput from  AbstractConditionViewHelper

Methods

void
setRenderingContext(RenderingContextInterface $renderingContext)

No description

void
injectObjectManager(ObjectManagerInterface $objectManager)

No description

void
injectLogger(LoggerInterface $logger)

Injects the (system) logger based on PSR-3.

AbstractViewHelper
registerArgument(string $name, string $type, string $description, bool $required = false, mixed $defaultValue = null, bool|null $escape = null)

Register a new argument. Call this method from your ViewHelper subclass inside the initializeArguments() method.

AbstractViewHelper
overrideArgument(string $name, string $type, string $description, bool $required = false, mixed $defaultValue = null, bool|null $escape = null)

Overrides a registered argument. Call this method from your ViewHelper subclass inside the initializeArguments() method if you want to override a previously registered argument.

initializeArguments()

Initializes the "then" and "else" arguments

static bool
evaluateCondition(array|null $arguments = null, RenderingContextInterface $renderingContext)

No description

static mixed
renderStatic(array $arguments, Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)

No description

static string
evaluateElseClosures(array $closures, array $conditionClosures, RenderingContextInterface $renderingContext)

No description

mixed
renderThenChild()

Returns value of "then" attribute.

string
renderElseChild()

Returns value of "else" attribute.

string
compile(string $argumentsName, string $closureName, string $initializationPhpCode, ViewHelperNode $node, TemplateCompiler $compiler)

The compiled ViewHelper adds two new ViewHelper arguments: thenClosure and elseClosure.

static string
renderResult(bool $isConditionFullfilled, array $arguments, RenderingContextInterface $renderingContext)

No description

string
render()

renders child if the role could be found in the security context, otherwise renders child.

Details

void setRenderingContext(RenderingContextInterface $renderingContext)

No description

Parameters

RenderingContextInterface $renderingContext

Return Value

void

void injectObjectManager(ObjectManagerInterface $objectManager)

No description

Parameters

ObjectManagerInterface $objectManager

Return Value

void

void injectLogger(LoggerInterface $logger)

Injects the (system) logger based on PSR-3.

Parameters

LoggerInterface $logger

Return Value

void

protected AbstractViewHelper registerArgument(string $name, string $type, string $description, bool $required = false, mixed $defaultValue = null, bool|null $escape = null)

Register a new argument. Call this method from your ViewHelper subclass inside the initializeArguments() method.

This exists only to throw our own exception!

Parameters

string $name

Name of the argument

string $type

Type of the argument

string $description

Description of the argument

bool $required

If true, argument is required. Defaults to false.

mixed $defaultValue

Default value of argument

bool|null $escape

Can be toggled to TRUE to force escaping of variables and inline syntax passed as argument value.

Return Value

AbstractViewHelper

$this, to allow chaining.

Exceptions

Exception

protected AbstractViewHelper overrideArgument(string $name, string $type, string $description, bool $required = false, mixed $defaultValue = null, bool|null $escape = null)

Overrides a registered argument. Call this method from your ViewHelper subclass inside the initializeArguments() method if you want to override a previously registered argument.

This exists only to throw our own exception!

Parameters

string $name

Name of the argument

string $type

Type of the argument

string $description

Description of the argument

bool $required

If true, argument is required. Defaults to false.

mixed $defaultValue

Default value of argument

bool|null $escape

Can be toggled to TRUE to force escaping of variables and inline syntax passed as argument value.

Return Value

AbstractViewHelper

$this, to allow chaining.

Exceptions

Exception

See also

registerArgument()

bool isEscapingInterceptorEnabled()

No description

Return Value

bool

initializeArguments()

Initializes the "then" and "else" arguments

static protected bool evaluateCondition(array|null $arguments = null, RenderingContextInterface $renderingContext)

No description

Parameters

array|null $arguments
RenderingContextInterface $renderingContext

Return Value

bool

static mixed renderStatic(array $arguments, Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)

No description

Parameters

array $arguments
Closure $renderChildrenClosure
RenderingContextInterface $renderingContext

Return Value

mixed

static protected string evaluateElseClosures(array $closures, array $conditionClosures, RenderingContextInterface $renderingContext)

No description

Parameters

array $closures
array $conditionClosures
RenderingContextInterface $renderingContext

Return Value

string

protected mixed renderThenChild()

Returns value of "then" attribute.

If then attribute is not set, iterates through child nodes and renders ThenViewHelper. If then attribute is not set and no ThenViewHelper and no ElseViewHelper is found, all child nodes are rendered

Return Value

mixed

rendered ThenViewHelper or contents of if no ThenViewHelper was found

protected string renderElseChild()

Returns value of "else" attribute.

If else attribute is not set, iterates through child nodes and renders ElseViewHelper. If else attribute is not set and no ElseViewHelper is found, an empty string will be returned.

Return Value

string

rendered ElseViewHelper or an empty string if no ThenViewHelper was found

string compile(string $argumentsName, string $closureName, string $initializationPhpCode, ViewHelperNode $node, TemplateCompiler $compiler)

The compiled ViewHelper adds two new ViewHelper arguments: thenClosure and elseClosure.

These contain closures which are be executed to render the then(), respectively else() case.

Parameters

string $argumentsName
string $closureName
string $initializationPhpCode
ViewHelperNode $node
TemplateCompiler $compiler

Return Value

string

static protected string renderResult(bool $isConditionFullfilled, array $arguments, RenderingContextInterface $renderingContext)

No description

Parameters

bool $isConditionFullfilled
array $arguments
RenderingContextInterface $renderingContext

Return Value

string

string render()

renders child if the role could be found in the security context, otherwise renders child.

Return Value

string

the rendered string