You are here

function advanced_help_preprocess_advanced_help_topic in Advanced Help 8

Implements hook_preprocess_HOOK().

File

./advanced_help.module, line 48

Code

function advanced_help_preprocess_advanced_help_topic(&$variables) {
  $module = $variables['module'];
  $topic = $variables['topic'];
  $type = $variables['type'];
  $advancedHelp = \Drupal::service('plugin.manager.advanced_help');
  $info = $variables['topic_exists'] = $advancedHelp
    ->getTopic($module, $topic);
  $variables['attributes'] = new Attribute();
  $variables['attributes']['class'] = [];
  $variables['attributes']['title'] = $info['title'];
  if (\Drupal::currentUser()
    ->hasPermission('view advanced help popup')) {
    $variables['attributes']['class'][] = 'advanced-help-link';
    $variables['attributes']['class'][] = 'use-ajax';
    $variables['attributes']['data-dialog-type'] = 'modal';
    $variables['attributes']['data-dialog-options'] = Json::encode([
      'width' => $info['popup width'],
      'height' => $info['popup height'],
    ]);
    $variables['#attached']['library'][] = 'advanced_help/help.icon';
  }
  switch ($type) {
    case 'icon':
      $variables['text'] = '<span>' . t('Help') . '</span>';
      break;
    case 'title':
      $variables['text'] = $info['title'];
      $variables['attributes']['class'][] = 'advanced-help-title';
      break;
    default:
      $variables['text'] = $type;
      $variables['attributes']['class'][] = 'advanced-help-title';
      break;
  }
}