You are here

function ImagecacheExternalTestCase::createTextField in Imagecache External 8

Same name and namespace in other branches
  1. 7.2 imagecache_external.test \ImagecacheExternalTestCase::createTextField()

Create a new text field to store test URL's.

Parameters

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

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

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

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

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

1 call to ImagecacheExternalTestCase::createTextField()
ImagecacheExternalTestCase::testCachingExternalImage in ./imagecache_external.test
Test caching an external image.

File

./imagecache_external.test, line 62
Tests for Imagecache External.

Class

ImagecacheExternalTestCase
Tests the functions for working with public/private file schemes.

Code

function createTextField($name, $type_name, $field_settings = [], $instance_settings = [], $widget_settings = []) {
  $field = [
    'field_name' => $name,
    'type' => 'text',
    'settings' => [],
    'cardinality' => !empty($field_settings['cardinality']) ? $field_settings['cardinality'] : 1,
  ];
  $field['settings'] = array_merge($field['settings'], $field_settings);
  field_create_field($field);
  $instance = [
    'field_name' => $field['field_name'],
    'entity_type' => 'node',
    'label' => $name,
    'bundle' => $type_name,
    'required' => !empty($instance_settings['required']),
    'settings' => [],
    'widget' => [
      'type' => 'text_textfield',
      'settings' => [],
    ],
  ];
  $instance['settings'] = array_merge($instance['settings'], $instance_settings);
  $instance['widget']['settings'] = array_merge($instance['widget']['settings'], $widget_settings);
  return field_create_instance($instance);
}