1 file.test FileTestHelper::createFileField($name, $type_name, $field_settings = array(), $instance_settings = array(), $widget_settings = array())

Creates a new file field.

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.

File

core/modules/file/tests/file.test, line 204
Tests for file.module.

Class

FileTestHelper
Provides methods specifically for testing File module's field handling.

Code

function createFileField($name, $type_name, $field_settings = array(), $instance_settings = array(), $widget_settings = array()) {
  $cardinality = 1;
  if (isset($field_settings['cardinality'])) {
    $cardinality = $field_settings['cardinality'];
    unset($field_settings['cardinality']);
  }
  $field = array(
    'field_name' => $name,
    'type' => 'file',
    'cardinality' => $cardinality,
    'settings' => $field_settings,
  );
  field_create_field($field);

  $this->attachFileField($name, 'node', $type_name, $instance_settings, $widget_settings);
}