Mercurial > hg > isophonics-drupal-site
comparison core/modules/help/src/Plugin/HelpSection/HookHelpSection.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\help\Plugin\HelpSection; | |
4 | |
5 use Drupal\Core\Extension\ModuleHandlerInterface; | |
6 use Drupal\Core\Link; | |
7 use Drupal\Core\Plugin\ContainerFactoryPluginInterface; | |
8 use Symfony\Component\DependencyInjection\ContainerInterface; | |
9 | |
10 /** | |
11 * Provides the module topics list section for the help page. | |
12 * | |
13 * @HelpSection( | |
14 * id = "hook_help", | |
15 * title = @Translation("Module overviews"), | |
16 * description = @Translation("Module overviews are provided by modules. Overviews available for your installed modules:"), | |
17 * ) | |
18 */ | |
19 class HookHelpSection extends HelpSectionPluginBase implements ContainerFactoryPluginInterface { | |
20 | |
21 /** | |
22 * The module handler. | |
23 * | |
24 * @var \Drupal\Core\Extension\ModuleHandlerInterface | |
25 */ | |
26 protected $moduleHandler; | |
27 | |
28 /** | |
29 * Constructs a HookHelpSection object. | |
30 * | |
31 * @param array $configuration | |
32 * A configuration array containing information about the plugin instance. | |
33 * @param string $plugin_id | |
34 * The plugin_id for the plugin instance. | |
35 * @param mixed $plugin_definition | |
36 * The plugin implementation definition. | |
37 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler | |
38 * The module handler service. | |
39 */ | |
40 public function __construct(array $configuration, $plugin_id, $plugin_definition, ModuleHandlerInterface $module_handler) { | |
41 parent::__construct($configuration, $plugin_id, $plugin_definition); | |
42 $this->moduleHandler = $module_handler; | |
43 } | |
44 | |
45 /** | |
46 * {@inheritdoc} | |
47 */ | |
48 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { | |
49 return new static( | |
50 $configuration, | |
51 $plugin_id, | |
52 $plugin_definition, | |
53 $container->get('module_handler') | |
54 ); | |
55 } | |
56 | |
57 /** | |
58 * {@inheritdoc} | |
59 */ | |
60 public function listTopics() { | |
61 $topics = []; | |
62 foreach ($this->moduleHandler->getImplementations('help') as $module) { | |
63 $title = $this->moduleHandler->getName($module); | |
64 $topics[$title] = Link::createFromRoute($title, 'help.page', ['name' => $module]); | |
65 } | |
66 | |
67 // Sort topics by title, which is the array key above. | |
68 ksort($topics); | |
69 return $topics; | |
70 } | |
71 | |
72 } |