Implements \Drupal\field\Plugin\Type\Widget\WidgetInterface::formElement().
Overrides WidgetInterface::formElement
public function formElement(array $items, $delta, array $element, $langcode, array &$form, array &$form_state) {
$defaults = array(
'fid' => 0,
'display' => !empty($this->field['settings']['display_default']),
'description' => '',
);
// Essentially we use the managed_file type, extended with some
// enhancements.
$element_info = element_info('managed_file');
$element += array(
'#type' => 'managed_file',
'#upload_location' => file_field_widget_uri($this->field, $this->instance),
'#upload_validators' => file_field_widget_upload_validators($this->field, $this->instance),
'#value_callback' => 'file_field_widget_value',
'#process' => array_merge($element_info['#process'], array(
'file_field_widget_process',
)),
'#progress_indicator' => $this
->getSetting('progress_indicator'),
// Allows this field to return an array instead of a single value.
'#extended' => TRUE,
);
$element['#weight'] = $delta;
$element['#default_value'] = !empty($items[$delta]) ? $items[$delta] : $defaults;
if (empty($element['#default_value']['fid'])) {
$element['#description'] = theme('file_upload_help', array(
'description' => $element['#description'],
'upload_validators' => $element['#upload_validators'],
));
}
return $element;
}