function File::preRenderFile

Same name in other branches
  1. 9 core/lib/Drupal/Core/Render/Element/File.php \Drupal\Core\Render\Element\File::preRenderFile()
  2. 8.9.x core/lib/Drupal/Core/Render/Element/File.php \Drupal\Core\Render\Element\File::preRenderFile()
  3. 11.x core/lib/Drupal/Core/Render/Element/File.php \Drupal\Core\Render\Element\File::preRenderFile()

Prepares a #type 'file' render element for input.html.twig.

For assistance with handling the uploaded file correctly, see the API provided by file.api.php.

Parameters

array $element: An associative array containing the properties of the element. Properties used: #title, #name, #size, #description, #required, #attributes.

Return value

array The $element with prepared variables ready for input.html.twig.

File

core/lib/Drupal/Core/Render/Element/File.php, line 74

Class

File
Provides a form element for uploading a file.

Namespace

Drupal\Core\Render\Element

Code

public static function preRenderFile($element) {
    $element['#attributes']['type'] = 'file';
    Element::setAttributes($element, [
        'id',
        'name',
        'size',
    ]);
    static::setAttributes($element, [
        'js-form-file',
        'form-file',
    ]);
    return $element;
}

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