You are here

function template_preprocess_yamlform_element_managed_file in YAML Form 8

Prepares variables for a managed file element.

Parameters

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

  • element: The form element.
  • value: The content for the element.
  • options Associative array of options for element.
  • file: The element's File object.
4 calls to template_preprocess_yamlform_element_managed_file()
template_preprocess_yamlform_element_audio_file in includes/yamlform.theme.inc
Prepares variables for an audio file element.
template_preprocess_yamlform_element_document_file in includes/yamlform.theme.inc
Prepares variables for a document file element.
template_preprocess_yamlform_element_image_file in includes/yamlform.theme.inc
Prepares variables for an image file element.
template_preprocess_yamlform_element_video_file in includes/yamlform.theme.inc
Prepares variables for a video file element.

File

includes/yamlform.theme.inc, line 720
Preprocessors and helper functions to make theming easier.

Code

function template_preprocess_yamlform_element_managed_file(array &$variables) {

  /** @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,
  ];
}