Further modules included.
[yaffs-website] / web / modules / contrib / advanced_help / advanced_help.module
1 <?php
2 use Drupal\Core\Template\Attribute;
3 use Drupal\Component\Serialization\Json;
4
5 /**
6  * Implements hook_menu_links_discovered_alter().
7  *
8  * Remove the admin menu in case the help module is enabled.
9  */
10 function advanced_help_menu_links_discovered_alter(&$links) {
11
12   if (Drupal::moduleHandler()->moduleExists('help')) {
13     unset($links['advanced_help.main']);
14   }
15 }
16
17 /**
18  * Implements hook_modules_installed().
19  */
20 function advanced_help_modules_installed($modules) {
21   $language = \Drupal::languageManager()->getCurrentLanguage()->getId();
22   \Drupal::cache('discovery')->invalidate('advanced_help_ini_' . $language);
23 }
24
25 /**
26  * Implements hook_theme().
27  */
28 function advanced_help_theme() {
29   return [
30     'advanced_help_topic' => [
31       'variables' => [
32         'module' => NULL,
33         'topic'  => NULL,
34         'type'   => 'icon',
35       ]
36     ]
37   ];
38 }
39
40 /**
41  * Implements hook_preprocess_HOOK().
42  */
43 function advanced_help_preprocess_advanced_help_topic(&$variables) {
44   $module = $variables['module'];
45   $topic  = $variables['topic'];
46   $type   = $variables['type'];
47
48   $advancedHelp = \Drupal::service('plugin.manager.advanced_help');
49   $info = $variables['topic_exists'] = $advancedHelp->getTopic($module, $topic);
50   $variables['attributes'] = new Attribute();
51   $variables['attributes']['class'] = [];
52   $variables['attributes']['title'] = $info['title'];
53
54   if (\Drupal::currentUser()->hasPermission('view advanced help popup')) {
55     $variables['attributes']['class'][] = 'advanced-help-link';
56     $variables['attributes']['class'][] = 'use-ajax';
57     $variables['attributes']['data-dialog-type'] = 'modal';
58     $variables['attributes']['data-dialog-options'] = Json::encode(['width' => $info['popup width'], 'height' => $info['popup height']]);
59     $variables['#attached']['library'][] = 'advanced_help/help.icon';
60   }
61   switch ($type) {
62     case 'icon':
63       $variables['text'] = '<span>' . t('Help') . '</span>';
64       break;
65
66     case 'title':
67       $variables['text'] = $info['title'];
68       $variables['attributes']['class'][] = 'advanced-help-title';
69       break;
70
71     default:
72       $variables['text'] = $type;
73       $variables['attributes']['class'][] = 'advanced-help-title';
74       break;
75   }
76 }