Search code examples
typo3partialsextbaseviewhelper

How to set the FrontendUserGroup in AllowViewHelper of VHS in a partial?


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');

Solution

  • 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.