You are here

function node_access_test_add_field in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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.

7 calls to node_access_test_add_field()
BulkFormAccessTest::setUp in core/modules/node/src/Tests/Views/BulkFormAccessTest.php
Sets up a Drupal site for running functional and integration tests.
FilePrivateTest::setUp in core/modules/file/src/Tests/FilePrivateTest.php
Sets up a Drupal site for running functional and integration tests.
ForumNodeAccessTest::setUp in core/modules/forum/src/Tests/ForumNodeAccessTest.php
Sets up a Drupal site for running functional and integration tests.
NodeAccessBaseTableTest::setUp in core/modules/node/src/Tests/NodeAccessBaseTableTest.php
Sets up a Drupal site for running functional and integration tests.
NodeAccessLanguageAwareCombinationTest::setUp in core/modules/node/src/Tests/NodeAccessLanguageAwareCombinationTest.php
Sets up a Drupal site for running functional and integration tests.

... See full list

File

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

Code

function node_access_test_add_field(NodeTypeInterface $type) {
  $field_storage = FieldStorageConfig::create(array(
    'field_name' => 'private',
    'entity_type' => 'node',
    'type' => 'integer',
  ));
  $field_storage
    ->save();
  $field = FieldConfig::create(array(
    'field_name' => 'private',
    'entity_type' => 'node',
    'bundle' => $type
      ->id(),
    'label' => 'Private',
  ));
  $field
    ->save();

  // Assign widget settings for the 'default' form mode.
  entity_get_form_display('node', $type
    ->id(), 'default')
    ->setComponent('private', array(
    'type' => 'number',
  ))
    ->save();
}