function NodeAccessJoinTest::setUp

Same name in other branches
  1. 10 core/modules/node/tests/src/Functional/NodeAccessJoinTest.php \Drupal\Tests\node\Functional\NodeAccessJoinTest::setUp()

Overrides NodeTestBase::setUp

File

core/modules/node/tests/src/Functional/NodeAccessJoinTest.php, line 75

Class

NodeAccessJoinTest
Tests Node Access on join.

Namespace

Drupal\Tests\node\Functional

Code

protected function setUp() : void {
    parent::setUp();
    node_access_test_add_field(NodeType::load('article'));
    $field_storage = FieldStorageConfig::create([
        'field_name' => 'related_article',
        'entity_type' => 'node',
        'translatable' => FALSE,
        'entity_types' => [],
        'settings' => [
            'target_type' => 'node',
        ],
        'type' => 'entity_reference',
    ]);
    $field_storage->save();
    $field = FieldConfig::create([
        'field_name' => 'related_article',
        'entity_type' => 'node',
        'bundle' => 'page',
        'label' => 'Related Article',
        'settings' => [
            'handler' => 'default',
            'handler_settings' => [
                // Reference a single vocabulary.
'target_bundles' => [
                    'article',
                ],
            ],
        ],
    ]);
    $field->save();
    $entity_display = \Drupal::service('entity_display.repository');
    $entity_display->getViewDisplay('node', 'page', 'default')
        ->setComponent('related_article')
        ->save();
    $entity_display->getFormDisplay('node', 'page', 'default')
        ->setComponent('related_article', [
        'type' => 'entity_reference_autocomplete',
    ])
        ->save();
    $field = FieldConfig::create([
        'field_name' => 'related_article',
        'entity_type' => 'node',
        'bundle' => 'article',
        'label' => 'Related Article',
        'settings' => [
            'handler' => 'default',
            'handler_settings' => [
                // Reference a single vocabulary.
'target_bundles' => [
                    'article',
                ],
            ],
        ],
    ]);
    $field->save();
    $entity_display->getViewDisplay('node', 'article', 'default')
        ->setComponent('related_article')
        ->save();
    $entity_display->getFormDisplay('node', 'article', 'default')
        ->setComponent('related_article', [
        'type' => 'entity_reference_autocomplete',
    ])
        ->save();
    node_access_rebuild();
    \Drupal::state()->set('node_access_test.private', TRUE);
}

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