node_access_test.module

Same filename in other branches
  1. 7.x modules/node/tests/node_access_test.module
  2. 9 core/modules/node/tests/modules/node_access_test/node_access_test.module
  3. 8.9.x core/modules/node/tests/modules/node_access_test/node_access_test.module
  4. 10 core/modules/node/tests/modules/node_access_test/node_access_test.module

File

core/modules/node/tests/modules/node_access_test/node_access_test.module

View source
<?php


/**
 * @file
 * Test module for testing the node access system.
 *
 * This module's functionality depends on the following state variables:
 * - node_access_test.no_access_uid: Used in NodeQueryAlterTest to enable the
 *   node_access_all grant realm.
 * - node_access_test.private: When TRUE, the module controls access for nodes
 *   with a 'private' property set, and inherits the default core access for
 *   nodes without this flag. When FALSE, the module controls access for all
 *   nodes.
 * - node_access_test_secret_catalan: When set to TRUE and using the Catalan
 *   'ca' language code, makes all Catalan content secret.
 *
 * @see node_access_test_node_grants()
 * @see \Drupal\node\Tests\NodeQueryAlterTest
 * @see \Drupal\node\Tests\NodeAccessBaseTableTest
 */
declare (strict_types=1);
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldConfig;
use Drupal\node\NodeTypeInterface;

/**
 * Adds the private field to a node type.
 *
 * @param \Drupal\node\NodeTypeInterface $type
 *   A node type entity.
 */
function node_access_test_add_field(NodeTypeInterface $type) {
    $field_storage = FieldStorageConfig::create([
        'field_name' => 'private',
        'entity_type' => 'node',
        'type' => 'integer',
    ]);
    $field_storage->save();
    $field = FieldConfig::create([
        'field_name' => 'private',
        'entity_type' => 'node',
        'bundle' => $type->id(),
        'label' => 'Private',
    ]);
    $field->save();
    // Assign widget settings for the 'default' form mode.
    \Drupal::service('entity_display.repository')->getFormDisplay('node', $type->id())
        ->setComponent('private', [
        'type' => 'number',
    ])
        ->save();
}

Functions

Title Deprecated Summary
node_access_test_add_field Adds the private field to a node type.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.