diff --git a/core/modules/help/css/help.module.css b/core/modules/help/css/help.module.css index 444e0cd..1994f96 100644 --- a/core/modules/help/css/help.module.css +++ b/core/modules/help/css/help.module.css @@ -2,20 +2,12 @@ .help-items { float: left; /* LTR */ width: 22%; - margin-right: 3%; /* LTR */ } [dir="rtl"] .help-items { float: right; margin-right: 0; margin-left: 3%; } -.help-items-last { - margin-right: 0; /* LTR */ -} -[dir="rtl"] .help-items-last { - margin-right: 0; - margin-left: 0; -} /** diff --git a/core/modules/help/help.module b/core/modules/help/help.module index 6d07405..98e6866 100644 --- a/core/modules/help/help.module +++ b/core/modules/help/help.module @@ -81,3 +81,40 @@ function help_preprocess_block(&$variables) { $variables['attributes']['role'] = 'complementary'; } } + +/** + * Implements hook_theme(). + */ +function help_theme() { + return array( + 'help_list' => array( + 'template' => 'help-list', + 'variables' => array('links' => NULL), + ), + ); +} + +/** + * Prepares variables for help list templates. + * + * Default template: help-list.html.twig. + * + * @param array $variables + * An associative array containing: + * - links: A list of links to render. + */ +function template_preprocess_help_list(&$variables) { + $links = $variables['links']; + $count = count($links); + // Four-column list. + $limit = ceil($count / 4); + $chunk = array_chunk($links, $limit, TRUE); + $variables['rows'] = array(); + foreach ($chunk as $list) { + $variables['rows'][] = array( + '#theme' => 'item_list__help', + '#items' => $list, + '#attributes' => array('class' => 'help-items'), + ); + } +} diff --git a/core/modules/help/lib/Drupal/help/Controller/HelpController.php b/core/modules/help/lib/Drupal/help/Controller/HelpController.php index 59cf945..2534b1d 100644 --- a/core/modules/help/lib/Drupal/help/Controller/HelpController.php +++ b/core/modules/help/lib/Drupal/help/Controller/HelpController.php @@ -19,52 +19,29 @@ class HelpController extends ControllerBase { /** * Prints a page listing a glossary of Drupal terminology. * - * @return string - * An HTML string representing the contents of help page. + * @return array + * An array as expected by drupal_render(). */ public function helpMain() { - $output = array( - '#attached' => array( - 'css' => array(drupal_get_path('module', 'help') . '/css/help.module.css'), - ), - '#markup' => '

' . $this->t('Help topics') . '

' . $this->t('Help is available on the following items:') . '

' . $this->helpLinksAsList(), - ); - return $output; - } - - /** - * Provides a formatted list of available help topics. - * - * @return string - * A string containing the formatted list. - */ - protected function helpLinksAsList() { $empty_arg = drupal_help_arg(); $module_info = system_rebuild_module_data(); $modules = array(); foreach ($this->moduleHandler()->getImplementations('help') as $module) { if ($this->moduleHandler()->invoke($module, 'help', array("admin/help#$module", $empty_arg))) { - $modules[$module] = $module_info[$module]->info['name']; + $name = $module_info[$module]->info['name']; + $modules[$module] = $this->l($name, 'help.page', array('name' => $module)); } } asort($modules); - // Output pretty four-column list. - $count = count($modules); - $break = ceil($count / 4); - $output = '
'; - - return $output; + return array( + '#theme' => 'help_list', + '#links' => $modules, + '#attached' => array( + 'css' => array(drupal_get_path('module', 'help') . '/css/help.module.css'), + ), + ); } /** diff --git a/core/modules/help/lib/Drupal/help/Tests/HelpTest.php b/core/modules/help/lib/Drupal/help/Tests/HelpTest.php index dd21f0e..f0f9ec7 100644 --- a/core/modules/help/lib/Drupal/help/Tests/HelpTest.php +++ b/core/modules/help/lib/Drupal/help/Tests/HelpTest.php @@ -73,7 +73,8 @@ public function testHelp() { $this->assertRaw(t('For more information, refer to the subjects listed in the Help Topics section or to the online documentation and support pages at drupal.org.', array('!docs' => 'https://drupal.org/documentation', '!support' => 'https://drupal.org/support', '!drupal' => 'https://drupal.org')), 'Help intro text correctly appears.'); // Verify that help topics text appears. - $this->assertRaw('

' . t('Help topics') . '

' . t('Help is available on the following items:') . '

', 'Help topics text correctly appears.'); + $this->assertRaw('

' . t('Help topics') . '

', 'Help page heading correctly appears.'); + $this->assertRaw('

' . t('Help is available on the following items:') . '

', 'Help topics text correctly appears.'); // Make sure links are properly added for modules implementing hook_help(). foreach ($this->getModuleList() as $module => $name) { diff --git a/core/modules/help/templates/help-list.html.twig b/core/modules/help/templates/help-list.html.twig new file mode 100644 index 0000000..211ba86 --- /dev/null +++ b/core/modules/help/templates/help-list.html.twig @@ -0,0 +1,20 @@ +{# +/** + * @file + * Default theme implementation to present a list of help items. + * + * Available variables: + * - rows: An array containing list of links to render. + * + * @ingroup themeable + */ +#} +

{{ 'Help topics'|t }}

+

{{ 'Help is available on the following items:'|t }}

+
+ {% if rows %} + {% for list in rows %} + {{ list }} + {% endfor %} + {% endif %} +