You are here

public function WebformHelpManager::buildVideoLink in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/WebformHelpManager.php \Drupal\webform\WebformHelpManager::buildVideoLink()

Build video link.

Parameters

string $video_id: Video id.

string|null $video_display: Video displa type.

string|null $title: Link title.

array $options: Link options.

Return value

array A renderable array containing a link to a video.

Overrides WebformHelpManagerInterface::buildVideoLink

1 call to WebformHelpManager::buildVideoLink()
WebformHelpManager::buildVideos in src/WebformHelpManager.php
Build the videos section.

File

src/WebformHelpManager.php, line 472

Class

WebformHelpManager
Webform help manager.

Namespace

Drupal\webform

Code

public function buildVideoLink($video_id, $video_display = NULL, $title = NULL, array $options = []) {
  $options += [
    'more' => TRUE,
    'class' => [
      'button',
      'button-action',
      'button--small',
      'button-webform-play',
    ],
  ];
  $video_info = $this
    ->getVideo($video_id);
  if (empty($video_info['youtube_id'])) {
    return [];
  }
  $link = [
    '#type' => 'link',
    '#title' => $title ?: $this
      ->t('Watch video'),
    '#prefix' => ' ',
  ];
  $video_display = $video_display ?: $this->configFactory
    ->get('webform.settings')
    ->get('ui.video_display');
  switch ($video_display) {
    case 'dialog':
      $route_name = 'webform.help.video';
      $route_parameters = [
        'id' => str_replace('_', '-', $video_info['id']),
      ];
      $route_options = $options['more'] ? [
        'query' => [
          'more' => 1,
        ],
      ] : [];
      return [
        '#url' => Url::fromRoute($route_name, $route_parameters, $route_options),
        '#attributes' => WebformDialogHelper::getModalDialogAttributes(WebformDialogHelper::DIALOG_WIDE, $options['class']),
        '#attached' => [
          'library' => [
            'webform/webform.ajax',
          ],
        ],
      ] + $link;
    case 'link':
      return [
        '#url' => Url::fromUri('https://youtu.be/' . $video_info['youtube_id']),
        '#attributes' => [
          'class' => $options['class'],
        ],
      ] + $link;
    case 'documentation':
      return [
        '#url' => Url::fromUri('https://youtu.be/' . $video_info['youtube_id']),
      ] + $link;
    case 'hidden':
    default:
      return [];
  }
}