You are here

protected function ContentEntityAutosaveFormTestBase::createMultipleTestField in Autosave Form 8

Creates a multiple field to test ajax submits with.

2 calls to ContentEntityAutosaveFormTestBase::createMultipleTestField()
ContentEntityAutosaveFormTestBase::doTestAutosaveStatesPurgingOnConfigEvent in tests/src/FunctionalJavascript/ContentEntity/ContentEntityAutosaveFormTestBase.php
Tests that autosave states are purged on modifying a form related config.
ContentEntityAutosaveFormTestBase::prepareSetUp in tests/src/FunctionalJavascript/ContentEntity/ContentEntityAutosaveFormTestBase.php
Prepares the test setup.

File

tests/src/FunctionalJavascript/ContentEntity/ContentEntityAutosaveFormTestBase.php, line 675

Class

ContentEntityAutosaveFormTestBase
Base test class for testing autosave support for entity forms.

Namespace

Drupal\Tests\autosave_form\FunctionalJavascript\ContentEntity

Code

protected function createMultipleTestField() {
  if (!FieldStorageConfig::loadByName($this->entityType, $this->unlimitedCardinalityField)) {

    // Create an unlimited cardinality field.
    FieldStorageConfig::create([
      'field_name' => $this->unlimitedCardinalityField,
      'entity_type' => $this->entityType,
      'type' => 'text',
      'cardinality' => -1,
    ])
      ->save();
  }
  if (!FieldConfig::loadByName($this->entityType, $this->bundle, $this->unlimitedCardinalityField)) {

    // Attach an instance of the field to the content type.
    FieldConfig::create([
      'field_name' => $this->unlimitedCardinalityField,
      'entity_type' => $this->entityType,
      'bundle' => $this->bundle,
      'label' => $this
        ->randomMachineName() . '_label',
    ])
      ->save();
    $this
      ->getEntityFormDisplay($this->entityType, $this->bundle, 'default')
      ->setComponent($this->unlimitedCardinalityField, [
      'type' => 'text_textfield',
    ])
      ->save();
  }
}