Commit 9da500af authored by catch's avatar catch

Issue #2494989 by catch, alexpott, vijaycs85: Don't render main help pages on...

Issue #2494989 by catch, alexpott, vijaycs85: Don't render main help pages on modules page just to generate help links - can lead to high memory usage on form submit
parent 24bd910f
......@@ -22,7 +22,8 @@
* Help block (provided by the core Help module), if the block is displayed on
* that page. The module overview help information is displayed by the Help
* module. It can be accessed from the page at admin/help or from the Extend
* Extend page.
* Extend page. If a module implements hook_help() the help system expects
* module overview help to be provided.
*
* For detailed usage examples of:
* - Module overview help, see content_translation_help(). Module overview
......
......@@ -68,9 +68,7 @@ public function helpMain() {
protected function helpLinksAsList() {
$modules = array();
foreach ($this->moduleHandler()->getImplementations('help') as $module) {
if ($this->moduleHandler()->invoke($module, 'help', array("help.page.$module", $this->routeMatch))) {
$modules[$module] = $this->moduleHandler->getName($module);
}
$modules[$module] = $this->moduleHandler->getName($module);
}
asort($modules);
......
......@@ -19,11 +19,16 @@ class HelpTest extends WebTestBase {
/**
* Modules to enable.
*
* The help_test module implements hook_help() but does not provide a module
* overview page.
*
* @var array.
*/
public static $modules = array('shortcut');
public static $modules = array('help_test');
// Tests help implementations of many arbitrary core modules.
/**
* Use the Standard profile to test help implementations of many core modules.
*/
protected $profile = 'standard';
/**
......@@ -71,6 +76,11 @@ public function testHelp() {
foreach ($this->getModuleList() as $module => $name) {
$this->assertLink($name, 0, format_string('Link properly added to @name (admin/help/@module)', array('@module' => $module, '@name' => $name)));
}
// Ensure that module which does not provide an module overview page is
// handled correctly.
$this->clickLink(\Drupal::moduleHandler()->getName('help_test'));
$this->assertRaw(t('No help is available for module %module.', array('%module' => \Drupal::moduleHandler()->getName('help_test'))));
}
/**
......
......@@ -44,6 +44,10 @@ public function testMainPageNoHelp() {
$this->drupalGet('admin/help');
$this->assertResponse(200);
$this->assertText('Help is available on the following items', 'Help page is found.');
$this->assertNoText('Hook menu tests', 'Making sure the test module menu_test does not display a help link on admin/help.');
$this->assertFalse(\Drupal::moduleHandler()->implementsHook('menu_test', 'help'), 'The menu_test module does not implement hook_help');
$this->assertNoText(\Drupal::moduleHandler()->getName('menu_test'), 'Making sure the test module menu_test does not display a help link on admin/help.');
$this->drupalGet('admin/help/menu_test');
$this->assertResponse(404, 'Getting a module overview help page for a module that does not implement hook_help() results in a 404.');
}
}
<?php
/**
* @file
* Test Help module.
*/
use \Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function help_test_help($route_name, RouteMatchInterface $route_match) {
// Do not implement a module overview page to test an empty implementation.
// @see \Drupal\help\Tests\HelpTest
}
......@@ -255,17 +255,17 @@ protected function buildRow(array $modules, Extension $module, $distribution) {
$row['description']['#markup'] = $this->t($module->info['description']);
$row['version']['#markup'] = $module->info['version'];
// Generate link for module's help page, if there is one.
// Generate link for module's help page. Assume that if a hook_help()
// implementation exists then the module provides an overview page, rather
// than checking to see if the page exists, which is costly.
$row['links']['help'] = array();
if ($this->moduleHandler->moduleExists('help') && $module->status && in_array($module->getName(), $this->moduleHandler->getImplementations('help'))) {
if ($this->moduleHandler->invoke($module->getName(), 'help', array('help.page.' . $module->getName(), $this->routeMatch))) {
$row['links']['help'] = array(
'#type' => 'link',
'#title' => $this->t('Help'),
'#url' => Url::fromRoute('help.page', ['name' => $module->getName()]),
'#options' => array('attributes' => array('class' => array('module-link', 'module-link-help'), 'title' => $this->t('Help'))),
);
}
$row['links']['help'] = array(
'#type' => 'link',
'#title' => $this->t('Help'),
'#url' => Url::fromRoute('help.page', ['name' => $module->getName()]),
'#options' => array('attributes' => array('class' => array('module-link', 'module-link-help'), 'title' => $this->t('Help'))),
);
}
// Generate link for module's permission, if the user has access to it.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment