function FileThemeHooks::preprocessManagedFile

Prepares variables for file form widget templates.

Default template: file-managed-file.html.twig.

Parameters

array<string,array> $variables: An associative array containing:

  • element: A render element representing the file.

File

core/modules/file/src/Hook/FileThemeHooks.php, line 196

Class

FileThemeHooks
Theme hooks for the file module.

Namespace

Drupal\file\Hook

Code

public function preprocessManagedFile(array &$variables) : void {
  $element = $variables['element'];
  $variables['attributes'] = [];
  if (isset($element['#id'])) {
    $variables['attributes']['id'] = $element['#id'];
  }
  if (!empty($element['#attributes']['class'])) {
    $variables['attributes']['class'] = (array) $element['#attributes']['class'];
  }
}

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