protected function FooBlock::blockAccess in Twig Tweak 3.x
Same name and namespace in other branches
- 8.2 tests/twig_tweak_test/src/Plugin/Block/FooBlock.php \Drupal\twig_tweak_test\Plugin\Block\FooBlock::blockAccess()
- 3.1.x tests/twig_tweak_test/src/Plugin/Block/FooBlock.php \Drupal\twig_tweak_test\Plugin\Block\FooBlock::blockAccess()
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
- tests/
twig_tweak_test/ src/ Plugin/ Block/ FooBlock.php, line 30
Class
- FooBlock
- Provides a foo block.
Namespace
Drupal\twig_tweak_test\Plugin\BlockCode
protected function blockAccess(AccountInterface $account) : AccessResult {
$result = AccessResult::allowedIf($account
->getAccountName() == 'User 1');
$result
->addCacheTags([
'tag_from_' . __FUNCTION__,
]);
$result
->setCacheMaxAge(35);
$result
->cachePerUser();
return $result;
}