You are here

public function FillPdfTestHelper::createImageField in FillPDF 7

Create a new image field.

Parameters

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

string $entity_type: The entity type that this field will be added to.

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

array $field_settings: (optional) A list of field settings that will be added to the defaults.

array $instance_settings: (optional) A list of instance settings that will be added to the instance defaults.

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

Return value

mixed The return value of field_create_instance().

Throws

\FieldException

See also

\ImageFieldTestCase::createImageField()

1 call to FillPdfTestHelper::createImageField()
FillPdfMergeTestCase::testPdfMerging in tests/FillPdfMergeTestCase.test
Test PDF merging.

File

tests/FillPdfTestHelper.test, line 174

Class

FillPdfTestHelper
Helper functions for FillPDF testing.

Code

public function createImageField($name, $entity_type, $bundle, array $field_settings = array(), array $instance_settings = array(), array $widget_settings = array()) {
  $field = array(
    'field_name' => $name,
    'type' => 'image',
    'settings' => array(),
    'cardinality' => !empty($field_settings['cardinality']) ? $field_settings['cardinality'] : 1,
  );
  $field['settings'] = array_merge($field['settings'], $field_settings);
  field_create_field($field);
  $instance = array(
    'field_name' => $field['field_name'],
    'entity_type' => $entity_type,
    'label' => $name,
    'bundle' => $bundle,
    'required' => !empty($instance_settings['required']),
    'settings' => array(),
    'widget' => array(
      'type' => 'image_image',
      'settings' => array(),
    ),
  );
  $instance['settings'] = array_merge($instance['settings'], $instance_settings);
  $instance['widget']['settings'] = array_merge($instance['widget']['settings'], $widget_settings);
  return field_create_instance($instance);
}