2 use Drupal\Core\Template\Attribute;
3 use Drupal\Component\Serialization\Json;
6 * Implements hook_menu_links_discovered_alter().
8 * Remove the admin menu in case the help module is enabled.
10 function advanced_help_menu_links_discovered_alter(&$links) {
12 if (Drupal::moduleHandler()->moduleExists('help')) {
13 unset($links['advanced_help.main']);
18 * Implements hook_modules_installed().
20 function advanced_help_modules_installed($modules) {
21 $language = \Drupal::languageManager()->getCurrentLanguage()->getId();
22 \Drupal::cache('discovery')->invalidate('advanced_help_ini_' . $language);
26 * Implements hook_theme().
28 function advanced_help_theme() {
30 'advanced_help_topic' => [
41 * Implements hook_preprocess_HOOK().
43 function advanced_help_preprocess_advanced_help_topic(&$variables) {
44 $module = $variables['module'];
45 $topic = $variables['topic'];
46 $type = $variables['type'];
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'];
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';
63 $variables['text'] = '<span>' . t('Help') . '</span>';
67 $variables['text'] = $info['title'];
68 $variables['attributes']['class'][] = 'advanced-help-title';
72 $variables['text'] = $type;
73 $variables['attributes']['class'][] = 'advanced-help-title';