You are here

function node_access_test_node_access in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/node/tests/modules/node_access_test/node_access_test.module \node_access_test_node_access()
  2. 9 core/modules/node/tests/modules/node_access_test/node_access_test.module \node_access_test_node_access()

Implements hook_node_access().

File

core/modules/node/tests/modules/node_access_test/node_access_test.module, line 149
Test module for testing the node access system.

Code

function node_access_test_node_access(NodeInterface $node, $op, AccountInterface $account) {
  $secret_catalan = \Drupal::state()
    ->get('node_access_test_secret_catalan') ?: 0;
  if ($secret_catalan && $node
    ->language()
    ->getId() == 'ca') {

    // Make all Catalan content secret.
    return AccessResult::forbidden()
      ->setCacheMaxAge(0);
  }

  // Grant access if a specific user is specified.
  if (\Drupal::state()
    ->get('node_access_test.allow_uid') === $account
    ->id()) {
    return AccessResult::allowed();
  }

  // No opinion.
  return AccessResult::neutral()
    ->setCacheMaxAge(0);
}