You are here

protected function SimplenewsTestBase::addField in Simplenews 8

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 src/Tests/SimplenewsPersonalizationFormsTest.php
Sets up a Drupal site for running functional and integration tests.
SimplenewsSynchronizeFieldsFormTest::setUp in src/Tests/SimplenewsSynchronizeFieldsFormTest.php
Sets up a Drupal site for running functional and integration tests.

File

src/Tests/SimplenewsTestBase.php, line 142
Simplenews test functions.

Class

SimplenewsTestBase
Base class for simplenews web tests.

Namespace

Drupal\simplenews\Tests

Code

protected function addField($type, $field_name, $entity_type, $bundle = NULL) {
  if (!isset($bundle)) {
    $bundle = $entity_type;
  }
  FieldStorageConfig::create(array(
    'field_name' => $field_name,
    'entity_type' => $entity_type,
    'type' => $type,
  ))
    ->save();
  FieldConfig::create(array(
    'field_name' => $field_name,
    'entity_type' => $entity_type,
    'bundle' => $bundle,
  ))
    ->save();
  entity_get_form_display($entity_type, $bundle, 'default')
    ->setComponent($field_name, array(
    'type' => 'string_textfield',
  ))
    ->save();
  entity_get_display($entity_type, $bundle, 'default')
    ->setComponent($field_name, array(
    'type' => 'string',
  ))
    ->save();
}