2
votes

I'd like to set the frontendUserGroup parameter in the AllowViewHelper but I don't know how to do that.

Sometimes (non-deterministic even if I flush the caches) there pop up this error:

The argument "frontendUserGroup" was registered with type "TYPO3\CMS\Extbase\Domain\Model\FrontendUserGroup", but is of type "string" in view helper "FluidTYPO3\Vhs\ViewHelpers\Security\AllowViewHelper"

Is it right to pass simply the reference of the usergroup as argument as follows?:

{namespace v=FluidTYPO3\Vhs\ViewHelpers}
...
<v:security.allow frontendUserGroup="3">
  <f:then>
    <span>Access granted</span>
  </f:then>
  <f:else>
    <span>Access denied</span>
  </f:else>
</v:security.allow>

The parameter is registered by the ViewHelper as follows:

$this->registerArgument('frontendUserGroup', 'TYPO3\CMS\Extbase\Domain\Model\FrontendUserGroup', 'The FrontendUserGroup to allow/deny');
2

2 Answers

4
votes

Based on your example you might just use the security.hasRole ViewHelper shipped with CMS Fluid:

<f:security.ifHasRole role="3">
  <f:then>
    <span>Access granted</span>
  </f:then>
  <f:else>
    <span>Access denied</span>
  </f:else>
</f:security.ifHasRole>

In contrary to the allow ViewHelper from EXT:vhs, this ViewHelper accepts the UID of a user group as argument. Instead of the UID you can also pass the title of the usergroup, but as far as I know this can be ambiguous.

3
votes

You should pass the actual FrontendUserGroup Object (TYPO3\CMS\Extbase\Domain\Model\FrontendUserGroup) to your view. Extbase provides the repository, that you can inject into your controller:

/**
 * @var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserGroupRepository
 * @inject
 */
protected $frontendUserGroupRepository;

public function myAction() {
        ....
        $this->view->assign('specialUserGroup', $this->frontendUserGroupRepository->findByUid(3));
}

Now pass this object to the viewHelper:

<v:security.allow frontendUserGroup="{specialUserGroup}">