You are here

public function WebformHelpManager::buildVideos in Webform 8.5

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

Build the videos section.

Parameters

bool $docs: Set to TRUE to build exportable HTML documentation.

Return value

array An render array containing the videos section.

Overrides WebformHelpManagerInterface::buildVideos

1 call to WebformHelpManager::buildVideos()
WebformHelpManager::buildIndex in src/WebformHelpManager.php
Build the main help page for the Webform module.

File

src/WebformHelpManager.php, line 338

Class

WebformHelpManager
Webform help manager.

Namespace

Drupal\webform

Code

public function buildVideos($docs = FALSE) {
  $video_display = $this->configFactory
    ->get('webform.settings')
    ->get('ui.video_display');
  $video_display = $docs ? 'documentation' : $video_display;
  if ($video_display === 'none') {
    return [];
  }
  $rows = [];
  foreach ($this->videos as $id => $video) {
    if (!empty($video['hidden'])) {
      continue;
    }
    $row = [];

    // Thumbnail.
    $video_thumbnail = [
      '#theme' => 'image',
      '#uri' => 'https://img.youtube.com/vi/' . $video['youtube_id'] . '/0.jpg',
      '#alt' => $video['title'],
    ];
    $row['thumbnail'] = [
      'data' => [
        'video' => $this
          ->buildVideoLink($id, $video_display, $video_thumbnail, [
          'class' => [],
          'more' => FALSE,
        ]),
      ],
      'width' => '200',
    ];

    // Content.
    $row['content'] = [
      'data' => [],
    ];
    $row['content']['data']['title'] = [
      '#markup' => $video['title'] . ' | ' . (isset($video['owner']) ? $video['owner'] : $this
        ->t('Jacob Rockowitz')),
      '#prefix' => '<h3>',
      '#suffix' => '</h3>',
    ];
    $row['content']['data']['content'] = [
      '#markup' => $video['content'],
      '#prefix' => '<p>',
      '#suffix' => '</p>',
    ];
    $row['content']['data']['link'] = [
      'video' => $this
        ->buildVideoLink($id, $video_display, NULL, [
        'more' => FALSE,
      ]),
      '#prefix' => '<p>',
      '#suffix' => '</p>',
    ];
    if ($video_links = $this
      ->getVideoLinks($id)) {
      $row['content']['data']['resources'] = [
        'title' => [
          '#markup' => $this
            ->t('Additional resources'),
          '#prefix' => '<div><strong>',
          '#suffix' => '</strong></div>',
        ],
        'links' => [
          '#theme' => 'links',
          '#links' => $video_links,
          '#attributes' => [
            'class' => [
              'webform-help-links',
            ],
          ],
        ],
      ];
    }
    $rows[$id] = [
      'data' => $row,
      'no_striping' => TRUE,
    ];
  }
  $build = [];
  if (!$docs) {

    // Filter.
    $build['filter'] = [
      '#type' => 'search',
      '#title' => $this
        ->t('Filter'),
      '#title_display' => 'invisible',
      '#size' => 30,
      '#placeholder' => $this
        ->t('Filter by videos'),
      '#attributes' => [
        'class' => [
          'webform-form-filter-text',
        ],
        'data-element' => 'table',
        'data-source' => 'tbody tr',
        'data-parent' => 'tr',
        'data-summary' => '.webform-help-videos-summary',
        'data-item-singlular' => $this
          ->t('video'),
        'data-item-plural' => $this
          ->t('videos'),
        'data-no-results' => '.webform-help-videos-no-results',
        'title' => $this
          ->t('Enter a keyword to filter by.'),
        'autofocus' => 'autofocus',
      ],
    ];

    // Display info.
    $build['info'] = [
      '#markup' => $this
        ->t('@total videos', [
        '@total' => count($rows),
      ]),
      '#prefix' => '<p class="webform-help-videos-summary">',
      '#suffix' => '</p>',
    ];

    // No results.
    $build['no_results'] = [
      '#type' => 'webform_message',
      '#message_message' => $this
        ->t('No videos found. Try a different search.'),
      '#message_type' => 'info',
      '#attributes' => [
        'class' => [
          'webform-help-videos-no-results',
        ],
      ],
    ];
    $build['table'] = [
      '#theme' => 'table',
      '#header' => [
        [
          'data' => '',
          'style' => 'padding:0; border-top-color: transparent',
          'class' => [
            RESPONSIVE_PRIORITY_LOW,
          ],
        ],
        [
          'data' => '',
          'style' => 'padding:0; border-top-color: transparent',
        ],
      ],
      '#rows' => $rows,
      '#attributes' => [
        'border' => 0,
        'cellpadding' => 2,
        'cellspacing' => 0,
      ],
    ];
    $build['#attached']['library'][] = 'webform/webform.admin';
    $build['#attached']['library'][] = 'webform/webform.help';
    $build['#attached']['library'][] = 'webform/webform.ajax';
  }
  else {
    $build['videos'] = [
      '#theme' => 'table',
      '#rows' => $rows,
      '#no_striping' => TRUE,
      '#attributes' => [
        'border' => 0,
        'cellpadding' => 2,
        'cellspacing' => 0,
      ],
    ];
  }
  return $build;
}