function FileFieldPathsTestCase::createImageField in File (Field) Paths 7
Creates 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.
2 calls to FileFieldPathsTestCase::createImageField()
- FileFieldPathsTextReplaceTestCase::testTextReplace in tests/
filefield_paths.text_replace.test - Test text replace with multiple file uploads.
- FileFieldPathsUpdatesCase::testRetroBasic in tests/
filefield_paths.update.test - Test basic Retroactive updates functionality.
File
- tests/
filefield_paths.test, line 63 - Tests for the File (Field) Paths module.
Class
- FileFieldPathsTestCase
- Class FileFieldPathsTestCase
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' => $name,
'label' => $name,
'entity_type' => 'node',
'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);
field_create_instance($instance);
$this
->drupalPost("admin/structure/types/manage/{$this->content_type}/fields/{$name}", array(), t('Save settings'));
}