protected function ContentEntityAutosaveFormTestBase::createRequiredTestField in Autosave Form 8
Creates a required test field to test ajax submits with.
1 call to ContentEntityAutosaveFormTestBase::createRequiredTestField()
- ContentEntityAutosaveFormTestBase::prepareSetUp in tests/
src/ FunctionalJavascript/ ContentEntity/ ContentEntityAutosaveFormTestBase.php - Prepares the test setup.
File
- tests/
src/ FunctionalJavascript/ ContentEntity/ ContentEntityAutosaveFormTestBase.php, line 705
Class
- ContentEntityAutosaveFormTestBase
- Base test class for testing autosave support for entity forms.
Namespace
Drupal\Tests\autosave_form\FunctionalJavascript\ContentEntityCode
protected function createRequiredTestField() {
if (!FieldStorageConfig::loadByName($this->entityType, $this->requiredField)) {
// Create a required test field.
FieldStorageConfig::create([
'field_name' => $this->requiredField,
'entity_type' => $this->entityType,
'type' => 'text',
'cardinality' => 1,
])
->save();
}
if (!FieldConfig::loadByName($this->entityType, $this->bundle, $this->requiredField)) {
// Attach an instance of the field to the content type.
FieldConfig::create([
'field_name' => $this->requiredField,
'entity_type' => $this->entityType,
'bundle' => $this->bundle,
'label' => $this->requiredField,
'required' => TRUE,
])
->save();
$this
->getEntityFormDisplay($this->entityType, $this->bundle, 'default')
->setComponent($this->requiredField, [
'type' => 'text_textfield',
])
->save();
}
}