public function ProtectedNodePrivateFile::createImageField in Protected Node 7
Same name and namespace in other branches
- 1.0.x tests/protected_node.private_file.test \ProtectedNodePrivateFile::createImageField()
Create a new image field.
Copy/pasted from image.test. Don't know why "new ImageFieldTestCase()" made fatal error.
Parameters
string $name: The name of the new field (all lowercase), exclude the "field_" prefix.
string $type_name: The node type that this field will be added to.
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 $widget_settings: A list of widget settings that will be added to the widget defaults.
Return value
array The $instance array with the id property filled in.
1 call to ProtectedNodePrivateFile::createImageField()
- ProtectedNodePrivateFile::setUp in tests/
protected_node.private_file.test - Prepare users for protected node's tests.
File
- tests/
protected_node.private_file.test, line 311 - Test protected node behavior with private files.
Class
- ProtectedNodePrivateFile
- Configure protected_node to use per node password and use private file field.
Code
public function createImageField($name, $type_name, 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' => '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);
}