function node_access_test_add_field

Same name in other branches
  1. 9 core/modules/node/tests/modules/node_access_test/node_access_test.module \node_access_test_add_field()
  2. 8.9.x core/modules/node/tests/modules/node_access_test/node_access_test.module \node_access_test_add_field()
  3. 11.x core/modules/node/tests/modules/node_access_test/node_access_test.module \node_access_test_add_field()

Adds the private field to a node type.

Parameters

\Drupal\node\NodeTypeInterface $type: A node type entity.

14 calls to node_access_test_add_field()
BulkFormAccessTest::setUp in core/modules/node/tests/src/Functional/Views/BulkFormAccessTest.php
Sets up the test.
FilePrivateTest::setUp in core/modules/file/tests/src/Functional/FilePrivateTest.php
FilterNodeAccessTest::setUp in core/modules/node/tests/src/Functional/Views/FilterNodeAccessTest.php
Sets up the test.
ForumNodeAccessTest::setUp in core/modules/forum/tests/src/Functional/ForumNodeAccessTest.php
ManageFieldsFunctionalTestBase::setUp in core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTestBase.php

... See full list

File

core/modules/node/tests/modules/node_access_test/node_access_test.module, line 122

Code

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();
}

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