function ImageFieldTestCase::createImageField
7.x image.test | ImageFieldTestCase::createImageField($name, $type_name, $field_settings = array(), $instance_settings = array(), $widget_settings = array()) |
Create a new image field.
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.
6 calls to ImageFieldTestCase::createImageField()
- ImageAdminStylesUnitTest::testStyleReplacement in drupal-7.x/
modules/ image/ image.test - Test deleting a style and choosing a replacement style.
- ImageFieldDefaultImagesTestCase::testDefaultImages in drupal-7.x/
modules/ image/ image.test - Tests CRUD for fields and fields instances with default images.
- ImageFieldDisplayTestCase::testImageFieldDefaultImage in drupal-7.x/
modules/ image/ image.test - Test use of a default image with an image field.
- ImageFieldDisplayTestCase::testImageFieldSettings in drupal-7.x/
modules/ image/ image.test - Tests for image field settings.
- ImageFieldDisplayTestCase::_testImageFieldFormatters in drupal-7.x/
modules/ image/ image.test - Test image formatters on node display.
File
- drupal-7.x/
modules/ image/ image.test, line 53 - Tests for image.module.
Class
- ImageFieldTestCase
- This class provides methods specifically for testing Image's field handling.
Code
function createImageField($name, $type_name, $field_settings = array(), $instance_settings = 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' => 'node',
'label' => $name,
'bundle' => $type_name,
'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);
}