You are here

function template_preprocess_webform_element_managed_file in Webform 6.x

Same name and namespace in other branches
  1. 8.5 includes/webform.theme.template.inc \template_preprocess_webform_element_managed_file()

Prepares variables for webform element managed file templates.

Parameters

array $variables: An associative array containing the following key:

  • element: The webform element.
  • value: The content for the element.
  • options Associative array of options for element.
  • file: The element's File object.
3 calls to template_preprocess_webform_element_managed_file()
template_preprocess_webform_element_audio_file in includes/webform.theme.template.inc
Prepares variables for webform element audio file templates.
template_preprocess_webform_element_document_file in includes/webform.theme.template.inc
Prepares variables for webform element document file templates.
template_preprocess_webform_element_video_file in includes/webform.theme.template.inc
Prepares variables for webform element video file templates.

File

includes/webform.theme.template.inc, line 937
Preprocessors and helper functions to make theming easier.

Code

function template_preprocess_webform_element_managed_file(array &$variables) {
  if (!empty($variables['file'])) {

    /** @var \Drupal\file\FileInterface $file */
    $file = $variables['file'];
    $variables['uri'] = file_create_url($file
      ->getFileUri());
    $variables['extension'] = strtolower(pathinfo($variables['uri'], PATHINFO_EXTENSION));
    $variables['type'] = \Drupal::service('file.mime_type.guesser')
      ->guess($variables['uri']);
    $variables['file_link'] = [
      '#theme' => 'file_link',
      '#file' => $file,
    ];
  }
}