Skip to content
Snippets Groups Projects
Verified Commit 973da437 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #2994748 by jhodgdon, andypost, Amber Himes Matz: Make a way for Help...

Issue #2994748 by jhodgdon, andypost, Amber Himes Matz: Make a way for Help Page Sections to be ordered
parent e4b25395
No related branches found
No related tags found
No related merge requests found
......@@ -72,9 +72,11 @@ function hook_help($route_name, \Drupal\Core\Routing\RouteMatchInterface $route_
* @see \Drupal\help\Annotation\HelpSection
* @see \Drupal\help\HelpSectionManager
*/
function hook_help_section_info_alter(&$info) {
function hook_help_section_info_alter(array &$info) {
// Alter the header for the module overviews section.
$info['hook_help']['header'] = t('Overviews of modules');
$info['hook_help']['title'] = t('Overviews of modules');
// Move the module overviews section to the end.
$info['hook_help']['weight'] = 500;
}
/**
......
......@@ -57,4 +57,13 @@ class HelpSection extends Plugin {
*/
public $permission = '';
/**
* An optional weight for the help section.
*
* The sections will be ordered by this weight on the help page.
*
* @var int
*/
public $weight = 0;
}
......@@ -85,6 +85,7 @@ public function helpMain() {
'#description' => $plugin->getDescription(),
'#empty' => $this->t('There is currently nothing in this section.'),
'#links' => [],
'#weight' => $plugin_definition['weight'],
];
$links = $plugin->listTopics();
......
......@@ -18,3 +18,10 @@ function more_help_page_test_help($route_name, RouteMatchInterface $route_match)
return ['#markup' => 'Help text from more_help_page_test_help module.'];
}
}
/**
* Implements hook_help_section_info_alter().
*/
function more_help_page_test_help_section_info_alter(array &$info) {
$info['hook_help']['weight'] = 500;
}
<?php
namespace Drupal\Tests\help\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Verify the order of the help page.
*
* @group help
*/
class HelpPageOrderTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['help', 'tour'];
/**
* Strings to search for on admin/help, in order.
*
* @var string[]
*/
protected $stringOrder = [
'Module overviews are provided',
'Tours guide you',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Create and log in user.
$account = $this->drupalCreateUser([
'access administration pages',
'view the administration theme',
'administer permissions',
'access tour',
]);
$this->drupalLogin($account);
}
/**
* Tests the order of the help page.
*/
public function testHelp() {
$pos = 0;
$this->drupalGet('admin/help');
$page_text = $this->getTextContent();
foreach ($this->stringOrder as $item) {
$new_pos = strpos($page_text, $item, $pos);
$this->assertTrue($new_pos > $pos, 'Order of ' . $item . ' is correct on help page');
$pos = $new_pos;
}
}
}
<?php
namespace Drupal\Tests\help\Functional;
/**
* Verify the order of the help page with an alter hook.
*
* @group help
*/
class HelpPageReverseOrderTest extends HelpPageOrderTest {
/**
* {@inheritdoc}
*/
protected static $modules = ['more_help_page_test'];
/**
* Strings to search for on admin/help, in order.
*
* These are reversed, due to the alter hook.
*
* @var string[]
*/
protected $stringOrder = [
'Tours guide you',
'Module overviews are provided',
];
}
......@@ -15,6 +15,7 @@
* @HelpSection(
* id = "help_topics",
* title = @Translation("Topics"),
* weight = -10,
* description = @Translation("Topics can be provided by modules or themes. Top-level help topics on your site:"),
* permission = "access administration pages"
* )
......
......@@ -15,6 +15,7 @@
* @HelpSection(
* id = "tour",
* title = @Translation("Tours"),
* weight = 10,
* description = @Translation("Tours guide you through workflows or explain concepts on various user interface pages. The tours with links in this list are on user interface landing pages; the tours without links will show on individual pages (such as when editing a View using the Views UI module). Available tours:"),
* permission = "access tour"
* )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment