Attach a file field to an entity.

Parameters

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

string $entity_type: The entity type this field will be added to.

string $bundle: The bundle this field will be added to.

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.

1 call to ExifFunctionalTestCase::attachFileField()
ExifFunctionalTestCase::createFileField in ./exif_functionaltests.php
Create a new file field.

File

./exif_functionaltests.php, line 56

Class

ExifFunctionalTestCase
Base class for functional tests for this module.

Code

public function attachFileField($name, $entity_type, $bundle, array $instance_settings = array(), array $widget_settings = array()) {
    $instance = array(
        'field_name' => $name,
        'label' => $name,
        'entity_type' => $entity_type,
        'bundle' => $bundle,
        'required' => !empty($instance_settings['required']),
        'settings' => array(),
        'widget' => array(
            'type' => 'file_generic',
            'settings' => array(),
        ),
    );
    $instance['settings'] = array_merge($instance['settings'], $instance_settings);
    $instance['widget']['settings'] = array_merge($instance['widget']['settings'], $widget_settings);
    field_create_instance($instance);
}