public function FileWidget::formElement

Implements \Drupal\field\Plugin\Type\Widget\WidgetInterface::formElement().

Overrides WidgetInterface::formElement

1 call to FileWidget::formElement()
ImageWidget::formElement in drupal/core/modules/image/lib/Drupal/image/Plugin/field/widget/ImageWidget.php
Overrides \Drupal\file\Plugin\field\widget\FileWidget::formElement().
1 method overrides FileWidget::formElement()
ImageWidget::formElement in drupal/core/modules/image/lib/Drupal/image/Plugin/field/widget/ImageWidget.php
Overrides \Drupal\file\Plugin\field\widget\FileWidget::formElement().

File

drupal/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php, line 167
Contains \Drupal\file\Plugin\field\widget\FileWidget.

Class

FileWidget
Plugin implementation of the 'file_generic' widget.

Namespace

Drupal\file\Plugin\field\widget

Code

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;
}