protected function SimplenewsTestBase::addField in Simplenews 3.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/SimplenewsTestBase.php \Drupal\Tests\simplenews\Functional\SimplenewsTestBase::addField()
Creates and saves a field storage and instance.
Parameters
string $type: The field type.
string $field_name: The name of the new field.
string $entity_type: The ID of the entity type to attach the field instance to.
string $bundle: (optional) The entity bundle. Defaults to same as $entity_type.
2 calls to SimplenewsTestBase::addField()
- SimplenewsPersonalizationFormsTest::setUp in tests/
src/ Functional/ SimplenewsPersonalizationFormsTest.php - SimplenewsSynchronizeFieldsFormTest::setUp in tests/
src/ Functional/ SimplenewsSynchronizeFieldsFormTest.php
File
- tests/
src/ Functional/ SimplenewsTestBase.php, line 153
Class
- SimplenewsTestBase
- Base class for simplenews web tests.
Namespace
Drupal\Tests\simplenews\FunctionalCode
protected function addField($type, $field_name, $entity_type, $bundle = NULL) {
if (!isset($bundle)) {
$bundle = $entity_type;
}
FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => $entity_type,
'type' => $type,
])
->save();
FieldConfig::create([
'field_name' => $field_name,
'entity_type' => $entity_type,
'bundle' => $bundle,
])
->save();
\Drupal::service('entity_display.repository')
->getFormDisplay($entity_type, $bundle)
->setComponent($field_name, [
'type' => 'string_textfield',
])
->save();
\Drupal::service('entity_display.repository')
->getViewDisplay($entity_type, $bundle)
->setComponent($field_name, [
'type' => 'string',
])
->save();
}