You are here

public static function UIkitVideo::preRenderUIkitVideo in UIkit Components 8.3

Pre-render callback: Sets the video attributes.

Doing so during pre_render gives modules a chance to alter the video.

Parameters

array $element: A renderable array.

Return value

array A renderable array.

File

src/Element/UIkitVideo.php, line 79

Class

UIkitVideo
Provides a render element for the Video component.

Namespace

Drupal\uikit_components\Element

Code

public static function preRenderUIkitVideo($element) {

  // Prepare the component options for the video.
  $component_options = '';
  if (!empty($element['#component_options'])) {
    $component_options = implode('; ', $element['#component_options']);
  }

  // Set the attributes for the video element.
  if (!empty($element['#video_sources'])) {
    if ($element['#display_controls']) {
      $element['#attributes']
        ->setAttribute('controls', '');
    }
    if ($element['#plays_inline']) {
      $element['#attributes']
        ->setAttribute('playsinline', '');
    }
  }
  $element['#attributes']
    ->setAttribute('data-uk-video', $component_options);
  return $element;
}