summaryrefslogtreecommitdiffstats
path: root/core/modules/rest/tests/modules/rest_test/rest_test.module
blob: 469b4c7fe1822df49266f300afa3d28c8a169348 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php

/**
 * @file
 * Contains hook implementations for testing REST module.
 */

use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Access\AccessResult;

/**
 * Implements hook_entity_field_access().
 *
 * @see \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::setUp()
 * @see \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::testPost()
 * @see \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::testPatch()
 */
function rest_test_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
  if ($field_definition->getName() === 'field_rest_test') {
    switch ($operation) {
      case 'view':
        // Never ever allow this field to be viewed: this lets EntityResourceTestBase::testGet() test in a "vanilla" way.
        return AccessResult::forbidden();
      case 'edit':
        return AccessResult::forbidden();
    }
  }

  // No opinion.
  return AccessResult::neutral();
}