You are here

protected static function FileWidget::getDescriptionFromElement in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php \Drupal\file\Plugin\Field\FieldWidget\FileWidget::getDescriptionFromElement()

Retrieves the file description from a field field element.

This helper static method is used by processMultiple() method.

Parameters

array $element: An associative array with the element being processed.

Return value

array|false A description of the file suitable for use in the administrative interface.

1 call to FileWidget::getDescriptionFromElement()
FileWidget::processMultiple in core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php
Form API callback: Processes a group of file_generic field elements.

File

core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php, line 517

Class

FileWidget
Plugin implementation of the 'file_generic' widget.

Namespace

Drupal\file\Plugin\Field\FieldWidget

Code

protected static function getDescriptionFromElement($element) {

  // Use the actual file description, if it's available.
  if (!empty($element['#default_value']['description'])) {
    return $element['#default_value']['description'];
  }

  // Otherwise, fall back to the filename.
  if (!empty($element['#default_value']['filename'])) {
    return $element['#default_value']['filename'];
  }

  // This is probably a newly uploaded file; no description is available.
  return FALSE;
}