You are here

function LingotekTestBase::createImageField in Lingotek Translation 8

Create a new image field.

Parameters

string $name: The name of the new field (all lowercase).

string $type_name: The bundle that this field will be added to.

string $entity_type_id: The entity type that this field will be added to. Defaults to 'node'

array $storage_settings: A list of field storage settings that will be added to the defaults.

array $field_settings: A list of instance settings that will be added to the instance defaults.

array $widget_settings: A list of widget settings that will be added to the widget defaults.

6 calls to LingotekTestBase::createImageField()
LingotekContentTranslationDocumentUploadHookTest::setUp in src/Tests/LingotekContentTranslationDocumentUploadHookTest.php
Sets up a Drupal site for running functional and integration tests.
LingotekContentTranslationPreSaveHookTest::setUp in src/Tests/LingotekContentTranslationPreSaveHookTest.php
Sets up a Drupal site for running functional and integration tests.
LingotekNodeEmbeddingTagsTranslationTest::setUp in src/Tests/LingotekNodeEmbeddingTagsTranslationTest.php
Sets up a Drupal site for running functional and integration tests.
LingotekNodeLocaleTranslationTest::setUp in src/Tests/LingotekNodeLocaleTranslationTest.php
Sets up a Drupal site for running functional and integration tests.
LingotekNodeTranslationTest::setUp in src/Tests/LingotekNodeTranslationTest.php
Sets up a Drupal site for running functional and integration tests.

... See full list

File

src/Tests/LingotekTestBase.php, line 44

Class

LingotekTestBase
Base class for Lingotek test. Performs authorization of the account.

Namespace

Drupal\lingotek\Tests

Code

function createImageField($name, $type_name, $entity_type_id = 'node', $storage_settings = array(), $field_settings = array(), $widget_settings = array()) {
  entity_create('field_storage_config', array(
    'field_name' => $name,
    'entity_type' => $entity_type_id,
    'type' => 'image',
    'settings' => $storage_settings,
    'cardinality' => !empty($storage_settings['cardinality']) ? $storage_settings['cardinality'] : 1,
  ))
    ->save();
  $field_config = entity_create('field_config', array(
    'field_name' => $name,
    'label' => $name,
    'entity_type' => $entity_type_id,
    'bundle' => $type_name,
    'required' => !empty($field_settings['required']),
    'settings' => $field_settings,
  ));
  $field_config
    ->save();
  entity_get_form_display($entity_type_id, $type_name, 'default')
    ->setComponent($name, array(
    'type' => 'image_image',
    'settings' => $widget_settings,
  ))
    ->save();
  entity_get_display($entity_type_id, $type_name, 'default')
    ->setComponent($name)
    ->save();
  return $field_config;
}