function FileFieldTestBase::attachFileField in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/file/src/Tests/FileFieldTestBase.php \Drupal\file\Tests\FileFieldTestBase::attachFileField()
Attaches 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 $field_settings: A list of field settings that will be added to the defaults.
array $widget_settings: A list of widget settings that will be added to the widget defaults.
1 call to FileFieldTestBase::attachFileField()
- FileFieldTestBase::createFileField in core/
modules/ file/ src/ Tests/ FileFieldTestBase.php - Creates a new file field.
File
- core/
modules/ file/ src/ Tests/ FileFieldTestBase.php, line 107 - Contains \Drupal\file\Tests\FileFieldTestBase.
Class
- FileFieldTestBase
- Provides methods specifically for testing File module's field handling.
Namespace
Drupal\file\TestsCode
function attachFileField($name, $entity_type, $bundle, $field_settings = array(), $widget_settings = array()) {
$field = array(
'field_name' => $name,
'label' => $name,
'entity_type' => $entity_type,
'bundle' => $bundle,
'required' => !empty($field_settings['required']),
'settings' => $field_settings,
);
entity_create('field_config', $field)
->save();
entity_get_form_display($entity_type, $bundle, 'default')
->setComponent($name, array(
'type' => 'file_generic',
'settings' => $widget_settings,
))
->save();
// Assign display settings.
entity_get_display($entity_type, $bundle, 'default')
->setComponent($name, array(
'label' => 'hidden',
'type' => 'file_default',
))
->save();
}