node_access_test.module
Same filename in other branches
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.