You are here

public static function S3fsCorsImageWidget::value in S3 File System CORS Upload 8

Form API callback. Retrieves the value for the file_generic field element.

This method is assigned as a #value_callback in formElement() method.

Overrides FileWidget::value

File

src/Plugin/Field/FieldWidget/S3fsCorsImageWidget.php, line 130

Class

S3fsCorsImageWidget
Plugin implementation of the 's3fs_cors_widget' widget.

Namespace

Drupal\s3fs_cors\Plugin\Field\FieldWidget

Code

public static function value($element, $input = FALSE, FormStateInterface $form_state = NULL) {
  if ($input) {

    // Checkboxes lose their value when empty.
    // If the display field is present make sure its unchecked value is saved.
    if (empty($input['display'])) {
      $input['display'] = $element['#display_field'] ? 0 : 1;
    }
  }

  // We depend on the managed file element to handle uploads.
  $return = S3fsCorsFile::valueCallback($element, $input, $form_state);

  // Ensure that all the required properties are returned even if empty.
  $return += [
    'fids' => [],
    'display' => 1,
    'description' => '',
  ];
  return $return;
}