Commit 6e6a0625 authored by Tim Bozeman's avatar Tim Bozeman Committed by Tim Bozeman
Browse files

Issue #3283895 by Tim Bozeman: D9!

parent ec9f08c5
Loading
Loading
Loading
Loading

README.md

0 → 100644
+43 −0
Original line number Diff line number Diff line
# Contextual Help

Provides pluggable toolbar help topics. Simply add a plugin to `/src/Plugin/Help/MyHelpTopic.php`.

#### Example plugin
```php
<?php

namespace Drupal\MY_MODULE\Plugin\Help;

use Drupal\contextual_help\HelpInterface;
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Clear Caches.
 *
 * @help(
 *   id = "clear_caches",
 *   title = @Translation("How to clear caches"),
 *   weight = 10,
 * )
 */
class MyHelpTopic implements HelpInterface {

  /**
   * {@inheritdoc}
   */
  public function applies(RouteMatchInterface $route_match): bool {
    return $route_match->getRouteName() === 'system.admin_content';
  }

  /**
   * {@inheritdoc}
   */
  public function display(): array {
    return [
      '#markup' => t('<p>Navigate Manage > Configuration > Development > Performance and click "Clear all caches".</p>'),
    ];
  }

}

```
+4 −0
Original line number Diff line number Diff line
name: Contextual Help
type: module
description: 'Provides a contextual user help system.'
core_version_requirement: ^8.8 || ^9
+5 −0
Original line number Diff line number Diff line
heading:
  version: 1.x
  css:
    theme:
      css/contextual-help.css: {}

contextual_help.module

0 → 100644
+57 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Provides help items.
 */

use Drupal\Core\Url;

/**
 * Implements hook_toolbar().
 */
function contextual_help_toolbar() {
  $items = [];

  $items['contextual_help'] = [
    '#cache' => [
      'contexts' => [
        'url.path',
      ],
    ],
  ];

  if (!\Drupal::currentUser()->hasPermission('access contextual help')) {
    return $items;
  }

  $help_topics = Drupal::service('contextual_help')->getHelpTopics();
  if ($help_topics) {
    $items['contextual_help'] += [
      '#type' => 'toolbar_item',
      'tab' => [
        '#type' => 'link',
        '#title' => t('Help'),
        '#url' => Url::fromRoute('<front>'),
        '#attributes' => [
          'id' => 'contextual-help',
        ],
      ],
      'tray' => [
        'visible_heading' => ['#markup' => t('<h3 id="contextual-help-heading">Help Topics</h3>')],
        'help' => $help_topics,
      ],
      '#weight' => 90,
      '#wrapper_attributes' => [
        'class' => ['contextual-help-button'],
      ],
      '#attached' => [
        'library' => [
          'contextual_help/heading',
        ],
      ],
    ];
  }

  return $items;
}
+2 −0
Original line number Diff line number Diff line
access contextual help:
  title: 'Access Contextual Help'
Loading