You are here

protected function FooBlock::blockAccess in Twig Tweak 8.2

Same name and namespace in other branches
  1. 3.x tests/twig_tweak_test/src/Plugin/Block/FooBlock.php \Drupal\twig_tweak_test\Plugin\Block\FooBlock::blockAccess()
  2. 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

self::access()

File

tests/twig_tweak_test/src/Plugin/Block/FooBlock.php, line 23

Class

FooBlock
Provides a foo block.

Namespace

Drupal\twig_tweak_test\Plugin\Block

Code

protected function blockAccess(AccountInterface $account) {
  $result = AccessResult::allowedIf($account
    ->getAccountName() == 'User 1');
  $result
    ->addCacheTags([
    'tag_from_' . __FUNCTION__,
  ]);
  $result
    ->setCacheMaxAge(35);
  $result
    ->cachePerUser();
  return $result;
}