You are here

protected function CommentAlterNodeReferenceTest::addNodeReferenceField in Comment Alter 8

Adds a node reference field to the parent enity.

Parameters

int $cardinality: Cardinality of the field.

Return value

string The name of the field which was created.

2 calls to CommentAlterNodeReferenceTest::addNodeReferenceField()
CommentAlterNodeReferenceTest::testEntityReferenceFieldMultiple in tests/src/Functional/CommentAlterNodeReferenceTest.php
Tests for multi-valued node reference field comment altering.
CommentAlterNodeReferenceTest::testEntityReferenceFieldSingle in tests/src/Functional/CommentAlterNodeReferenceTest.php
Tests for single valued node reference field comment altering.

File

tests/src/Functional/CommentAlterNodeReferenceTest.php, line 35

Class

CommentAlterNodeReferenceTest
Tests the comment alter module functions for node reference fields.

Namespace

Drupal\Tests\comment_alter\Functional

Code

protected function addNodeReferenceField($cardinality) {
  $referenced = $this
    ->createContentType();
  $referencedType = $referenced
    ->id();
  $this->targetNode = $this
    ->createNode([
    'type' => $referenced
      ->id(),
  ]);
  return $this
    ->addField('entity_reference', 'entity_reference_autocomplete', [
    'settings' => [
      'target_type' => 'node',
    ],
    'cardinality' => $cardinality,
  ], [
    'handler' => 'default',
    'handler_settings' => [
      // Reference a single vocabulary.
      'target_bundles' => [
        $referenced
          ->id(),
      ],
      // Enable auto-create.
      'auto_create' => TRUE,
    ],
  ]);
}