如何部分设置 VHS 的 AllowViewHelper 中的 FrontendUserGroup?

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

我想在 AllowViewHelper 中设置 frontendUserGroup 参数,但我不知道该怎么做。

有时(即使我刷新缓存也不确定)会弹出此错误:

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"

将用户组的引用作为参数传递如下是否正确?:

{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>

ViewHelper注册的参数如下:

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

您应该将实际的 FrontendUserGroup 对象 (TYPO3\CMS\Extbase\Domain\Model\FrontendUserGroup) 传递给您的视图。 Extbase 提供存储库,您可以将其注入控制器:

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

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

现在将此对象传递给 viewHelper:

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

根据您的示例,您可能只使用 CMS Fluid 附带的 security.hasRole ViewHelper:

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

与 EXT:vhs 中的 allow ViewHelper 相反,此 ViewHelper 接受用户组的 UID 作为参数。除了 UID,您还可以传递用户组的标题,但据我所知这可能不明确。