You are here

public function NodeFormBlock::blockAccess in Form Block 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Block/NodeFormBlock.php \Drupal\formblock\Plugin\Block\NodeFormBlock::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

src/Plugin/Block/NodeFormBlock.php, line 157

Class

NodeFormBlock
Provides a block for node forms.

Namespace

Drupal\formblock\Plugin\Block

Code

public function blockAccess(AccountInterface $account) {
  $access_control_handler = $this->entityTypeManager
    ->getAccessControlHandler('node');

  // NodeAccessControlHandler::createAccess() adds user.permissions
  // as a cache context to the returned AccessResult.

  /* @var $result \Drupal\Core\Access\AccessResult */
  $result = $access_control_handler
    ->createAccess($this->configuration['type'], $account, [], TRUE);

  // Add the node type as a cache dependency.
  $node_type = $node_type = NodeType::load($this->configuration['type']);
  $result
    ->addCacheTags($node_type
    ->getCacheTags());
  return $result;
}