You are here

function template_preprocess_yamlform_help in YAML Form 8

Prepares variables for yamlform help.

Default template: yamlform_help.html.twig.

Parameters

array $variables: An associative array containing:

  • title: Help title.
  • content: Help content.

File

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

Code

function template_preprocess_yamlform_help(array &$variables) {
  $help_info = $variables['info'];
  $variables += $help_info;
  $help = [];
  if (is_array($help_info['content'])) {
    $help['content'] = $help_info['content'];
  }
  else {
    $help['content'] = [
      '#markup' => $help_info['content'],
    ];
  }

  // Build watch video link.

  /** @var \Drupal\yamlform\YamlFormHelpManagerInterface $help_manager */
  $help_manager = \Drupal::service('yamlform.help_manager');

  // If help info load the video else this is the video info.
  $video_info = isset($help_info['video_id']) ? $help_manager
    ->getVideo($help_info['video_id']) : $help_info;
  if (!empty($video_info['youtube_id'])) {
    $classes = [
      'button',
      'button-action',
      'button--small',
      'button-yamlform-play',
    ];
    $video_display = \Drupal::config('yamlform.settings')
      ->get('ui.video_display');
    switch ($video_display) {
      case 'dialog':
        $help['link'] = [
          '#type' => 'link',
          '#title' => t('Watch video'),
          '#url' => Url::fromRoute('yamlform.help', [
            'id' => str_replace('_', '-', $video_info['id']),
          ]),
          '#attributes' => YamlFormDialogHelper::getModalDialogAttributes(1000, $classes),
          '#prefix' => ' ',
        ];
        break;
      case 'link':
        $help['link'] = [
          '#type' => 'link',
          '#title' => t('Watch video'),
          '#url' => Url::fromUri('https://youtu.be/' . $video_info['youtube_id']),
          '#attributes' => [
            'class' => $classes,
          ],
          '#prefix' => ' ',
        ];
        break;
      case 'hidden':
      default:
        break;
    }
  }
  $variables['help'] = $help;
}