You are here

function template_preprocess_amp_video in Accelerated Mobile Pages (AMP) 8

Same name and namespace in other branches
  1. 8.2 amp.module \template_preprocess_amp_video()

Prepares variables for amp video templates.

Default template: amp-video.html.twig.

Parameters

array $variables: An associative array containing:

  • file: A file object to which the link will be created.
  • attributes: An associative array of attributes to be placed on the amp-video tag.

File

./amp.module, line 304

Code

function template_preprocess_amp_video(&$variables) {
  $file = $variables['file'];
  $file_entity = $file instanceof File ? $file : File::load($file->fid);
  $variables['src'] = file_create_url($file_entity
    ->getFileUri());

  // amp-video can only be displayed if the src for the video is https.
  $variables['scheme'] = \Drupal::service('file_system')
    ->uriScheme($file_entity
    ->getFileUri());

  // Create attributes object.
  $variables['attributes'] = new Attribute($variables['attributes']);

  // Use the description as the title text if available.
  if (empty($variables['description'])) {
    $title_text = $file_entity
      ->getFilename();
  }
  else {
    $title_text = $variables['description'];
  }
  $variables['attributes']['title'] = $title_text;
}