You are here

protected function AnimatedGifFunctionalTestBase::createFileField in Animated GIF 8

Helper method to create the image field.

Parameters

string $entityType: The entity type.

string $bundle: The bundle name.

string $fieldName: The field name.

Throws

\Drupal\Core\Entity\EntityStorageException

1 call to AnimatedGifFunctionalTestBase::createFileField()
AnimatedGifFieldTest::setUp in tests/src/Functional/AnimatedGifFieldTest.php

File

tests/src/Functional/AnimatedGifFunctionalTestBase.php, line 131

Class

AnimatedGifFunctionalTestBase
Base class for Animated GIF functional tests.

Namespace

Drupal\Tests\animated_gif\Functional

Code

protected function createFileField(string $entityType, string $bundle, string $fieldName) : void {
  if (!FieldStorageConfig::loadByName($entityType, $fieldName)) {
    FieldStorageConfig::create([
      'field_name' => $fieldName,
      'entity_type' => $entityType,
      'type' => 'image',
      'settings' => [
        'alt_field_required' => 0,
      ],
      'cardinality' => 1,
    ])
      ->save();
  }
  if (!FieldConfig::loadByName($entityType, $bundle, $fieldName)) {
    FieldConfig::create([
      'field_name' => $fieldName,
      'entity_type' => $entityType,
      'bundle' => $bundle,
      'label' => $fieldName,
    ])
      ->save();
  }
}