protected function TocBlockBase::blockAccess in TOC API 8
Indicates whether the block should be shown.
Blocks with specific access checking should override this method rather than access(), in order to avoid repeating the handling of the $return_as_object argument.
Parameters
\Drupal\Core\Session\AccountInterface $account: The user session for which to check access.
Return value
\Drupal\Core\Access\AccessResult The access result.
Overrides BlockPluginTrait::blockAccess
See also
File
- src/
Plugin/ Block/ TocBlockBase.php, line 38
Class
- TocBlockBase
- Provides a base TOC block which displays the current TOC module's TOC in a block.
Namespace
Drupal\toc_api\Plugin\BlockCode
protected function blockAccess(AccountInterface $account) {
$this
->getCurrentTocId();
/** @var \Drupal\toc_api\TocManagerInterface $toc_manager */
$toc_manager = \Drupal::service('toc_api.manager');
// Get the new TOC instance and see if it is visible and should be
// displayed in a block.
$toc = $toc_manager
->getToc($this
->getCurrentTocId());
if (!$toc || !$toc
->isVisible() || !$toc
->isBlock()) {
return AccessResult::forbidden();
}
else {
return AccessResult::allowed();
}
}