protected function ImageLinkFormatterTestCase::createField in Image Link Formatter 7
Programmatically create a field and its instance, attached to nodes.
Parameters
string $field_name: The name of the new field (all lowercase), exclude the "field_" prefix.
string $field_type: The storage backend specified in the 'field_storage_default' system variable.
string $widget_type: The default widget specified in hook_field_info().
array $field_settings: A list of field settings that will be added to the defaults.
array $instance_settings: A list of instance settings that will be added to the instance defaults.
array $display: Settings for the 'default' view mode will be added if not present, and each view mode in the definition will be completed with the following default values:
- label: 'above'
- type: the default formatter specified in hook_field_info().
- settings: each omitted setting is given the default value specified in hook_field_formatter_info().
array $widget_settings: A list of widget settings that will be added to the widget defaults.
Return value
array Field instance attached to a node content type.
See also
1 call to ImageLinkFormatterTestCase::createField()
- ImageLinkFormatterFieldUITestCase::testFormatterManageDisplaySettings in ./
image_link_formatter.test - Test Image Link formatter manage display settings.
File
- ./
image_link_formatter.test, line 112 - Test the Image Link Formatter module.
Class
- ImageLinkFormatterTestCase
- Provides common functionality for the Image Link Formatter test classes.
Code
protected function createField($field_name, $field_type, $widget_type, $field_settings = array(), $instance_settings = array(), $display = array(), $widget_settings = array()) {
// Create field with a cardinality assumed to be 1 by default.
$field = array(
'field_name' => $field_name,
'type' => $field_type,
'settings' => $field_settings,
'cardinality' => !empty($field_settings['cardinality']) ? $field_settings['cardinality'] : 1,
);
field_create_field($field);
// Create field instance attached to nodes.
$instance = array(
'field_name' => $field['field_name'],
'entity_type' => 'node',
'label' => $field_name,
'bundle' => $this->bundle,
'required' => !empty($instance_settings['required']),
'settings' => $instance_settings,
'display' => $display,
'widget' => array(
'type' => $widget_type,
'settings' => $widget_settings,
),
);
return field_create_instance($instance);
}