You are here

function ImageFieldTestBase::createImageField in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/image/src/Tests/ImageFieldTestBase.php \Drupal\image\Tests\ImageFieldTestBase::createImageField()

Create a new image field.

Parameters

string $name: The name of the new field (all lowercase), exclude the "field_" prefix.

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

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.

14 calls to ImageFieldTestBase::createImageField()
ImageAdminStylesTest::testConfigImport in core/modules/image/src/Tests/ImageAdminStylesTest.php
Tests image style configuration import that does a delete.
ImageAdminStylesTest::testStyleReplacement in core/modules/image/src/Tests/ImageAdminStylesTest.php
Test deleting a style and choosing a replacement style.
ImageFieldAttributesTest::setUp in core/modules/rdf/src/Tests/ImageFieldAttributesTest.php
Sets up a Drupal site for running functional and integration tests.
ImageFieldDefaultImagesTest::testDefaultImages in core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php
Tests CRUD for fields and fields fields with default images.
ImageFieldDisplayTest::testImageFieldDefaultImage in core/modules/image/src/Tests/ImageFieldDisplayTest.php
Test use of a default image with an image field.

... See full list

File

core/modules/image/src/Tests/ImageFieldTestBase.php, line 71
Contains \Drupal\image\Tests\ImageFieldTestBase.

Class

ImageFieldTestBase
This class provides methods specifically for testing Image's field handling.

Namespace

Drupal\image\Tests

Code

function createImageField($name, $type_name, $storage_settings = array(), $field_settings = array(), $widget_settings = array()) {
  entity_create('field_storage_config', array(
    'field_name' => $name,
    'entity_type' => 'node',
    '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' => 'node',
    'bundle' => $type_name,
    'required' => !empty($field_settings['required']),
    'settings' => $field_settings,
  ));
  $field_config
    ->save();
  entity_get_form_display('node', $type_name, 'default')
    ->setComponent($name, array(
    'type' => 'image_image',
    'settings' => $widget_settings,
  ))
    ->save();
  entity_get_display('node', $type_name, 'default')
    ->setComponent($name)
    ->save();
  return $field_config;
}