function FileWidget::getDescriptionFromElement

Same name in other branches
  1. 8.9.x core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php \Drupal\file\Plugin\Field\FieldWidget\FileWidget::getDescriptionFromElement()
  2. 10 core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php \Drupal\file\Plugin\Field\FieldWidget\FileWidget::getDescriptionFromElement()
  3. 11.x core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php \Drupal\file\Plugin\Field\FieldWidget\FileWidget::getDescriptionFromElement()

Retrieves the file description from a 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 522

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.