You are here

protected function CckSelectOtherTestBase::createSelectOtherListField in CCK Select Other 8

Creates a select other field on the content type.

Parameters

string $type: The field type plugin ID.

array $fieldInfo: The field storage configuration.

array $instanceInfo: The field configuration.

Return value

\Drupal\Core\Entity\EntityInterface|\Drupal\field\Entity\FieldStorageConfig The field config instance.

Throws

\Drupal\Core\Entity\EntityStorageException

7 calls to CckSelectOtherTestBase::createSelectOtherListField()
CckSelectOtherDefaultValueTest::testDefaultValue in tests/src/Functional/CckSelectOtherDefaultValueTest.php
Asserts that default value is selected.
CckSelectOtherEmptyTest::testEmpty in tests/src/Functional/CckSelectOtherEmptyTest.php
Asserts field validation for required attribute.
CckSelectOtherFieldTypeTest::testField in tests/src/Functional/CckSelectOtherFieldTypeTest.php
Asserts that a user can save regular and other field values.
CckSelectOtherHtmlEntitiesTest::testHtmlEntities in tests/src/Functional/CckSelectOtherHtmlEntitiesTest.php
Asserts HTML entities are not double-encoded.
CckSelectOtherMultipleFieldTest::setUp in tests/src/Functional/CckSelectOtherMultipleFieldTest.php

... See full list

File

tests/src/Functional/CckSelectOtherTestBase.php, line 78

Class

CckSelectOtherTestBase
CCK Select Other functional test base class.

Namespace

Drupal\Tests\cck_select_other\Functional

Code

protected function createSelectOtherListField($type = 'list_string', array $fieldInfo = [], array $instanceInfo = []) {
  $random = $this
    ->getRandomGenerator();

  // Create field storage instance.
  $storage_values = NestedArray::mergeDeep($fieldInfo, [
    'field_name' => strtolower($random
      ->name(8, TRUE)),
    'entity_type' => 'node',
    'type' => $type,
  ]);
  $fieldStorage = FieldStorageConfig::create($storage_values);
  $fieldStorage
    ->save();
  $this
    ->assertNotNull($fieldStorage
    ->id(), 'Successfully saved field storage configuration.');

  // Create field instance.
  $field_values = NestedArray::mergeDeep($instanceInfo, [
    'field_name' => $fieldStorage
      ->getName(),
    'entity_type' => 'node',
    'bundle' => $this->contentType
      ->id(),
    'label' => $random
      ->string(15),
  ]);
  $field = FieldConfig::create($field_values);
  $field
    ->save();
  $this
    ->assertNotNull($field
    ->id(), 'Successfully saved field configuration.');

  // Create form and display entities for select other field.
  $display_id = 'node.' . $this->contentType
    ->id() . '.default';
  $formDisplay = EntityFormDisplay::load($display_id);
  $formDisplay
    ->setComponent($fieldStorage
    ->getName(), [
    'type' => 'cck_select_other',
  ]);
  $formDisplay
    ->save();
  $viewDisplay = EntityViewDisplay::load($display_id);
  $viewDisplay
    ->setComponent($fieldStorage
    ->getName(), [
    'type' => 'cck_select_other',
  ]);
  $viewDisplay
    ->save();
  return $fieldStorage;
}