Problem/Motivation
On #2920309: Add experimental module for Help Topics, one thing that came up was that we wanted to move the new section for Help Topics on admin/help, so that it appears before the section for Module Overviews (hook_help() output).
Sections on admin/help are created by plugins of type HelpSection (each is an annotated class). Currently, they have no weight, so they are just ordered arbitrarily by the HelpSectionPluginManager.
Proposed resolution
Add a weight property to the HelpSection annotation, so that HelpSection plugins can be ordered on the admin/help page. Proposed order:
- [-10] Help Topics (if #2920309: Add experimental module for Help Topics gets in)
- [0] Module Overviews (hook_help() output)
- [10] Tours
Proposed weights for those sections are in [] in that list, with space left so that contributed modules defining HelpSection plugins can insert their sections wherever they want.
Remaining tasks
1. [done] Make a patch that adds weight functionality and weights.
2. [done] Write a test. Should include a testing module that demonstrates the order can be altered via a hook that alters the plugin data.
https://api.drupal.org/api/drupal/core%21modules%21help%21help.api.php/f...
3. [done] Change the function body in that hook (in the help.api.php file) so that the sample code also alters the weights, as that is the most likely use for the hook. Old function body was actually not valid, so that is also updated.
User interface changes
The order of sections on admin/help will be governed by plugin weight, instead of kind of random.
API changes
There will be a new property for HelpSection plugin annotation (given a default value of 0 for backwards compatibility).
Data model changes
None.
Release notes snippet
Modules can add sections to the admin/help page by defining a HelpSection plugin. See
https://api.drupal.org/api/drupal/core%21modules%21help%21src%21HelpSect...
for more information about HelpSection plugins.
These plugins can now provide a weight property in their annotation, in order to define their position on the admin/help page. Existing core sections are given the following weights:
- Help topics (experimental module): -10
- hook_help() module overviews: 0
- Tours: 10
Example annotation with weight, for a HelpSection plugin:
* @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"
* )
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | 2994748-weight-18.patch | 6.26 KB | andypost |
| #18 | interdiff.txt | 3.54 KB | andypost |
Comments
Comment #2
andypostOn other hand any list of help section plugins instantiated by block which is rendered in some context ... So block could store in its config list if plug-in ids already ordered
Another option is event to collect/sort filtered plugin definitions https://www.drupal.org/node/2961820
Comment #4
jhodgdonI'm going to work on this today.
Comment #5
jhodgdonWell, this turned out to be pretty simple. Here's a patch. Do we need a test? I tested it manually by looking at the order of the page (which happened to be Module Overviews, Topics, then Tours), and then applying the patch and clearing the cache, and the new order is Topics, then Overviews, then Tours.
Comment #6
jhodgdonMight help if I actually uploaded the patch. :)
Comment #7
jhodgdonComment #8
jhodgdonComment #9
andypostNice! Sure it needs test and testing module that will show how using hook plugin alter to reorder sections
Meantime question - are we allow any UI for reordering outofbox?
Comment #10
jhodgdonI do not think we need a UI, and that was not in the original proposal. If someone wants to alter it on their own web site, and we have an alter hook, that should be good enough. Good idea for the test, adding that to the issue summary, and marking as Needs Work for the test.
And I think we should add that alteration to the function body of
https://api.drupal.org/api/drupal/core%21modules%21help%21help.api.php/f...
as part of the sample code.
Comment #11
jhodgdonActually I think the function body in that help.api.php file is just wrong. There is no "header" property of those plugins. ?!?
Comment #12
jhodgdonI'm working on the test now... should have a patch later today.
Comment #13
jhodgdonOK, here's a patch that adds two tests (both pass locally), and also updates the api.php file so the alter hook body there actually would work.
Comment #14
jhodgdonTests pass on the bot too. Here's a fix for the coding standards problems... I think this is probably ready... Any thoughts @andypost?
Also adding release notes snippet to the issue summary for the change notice.
Comment #15
andypostQuick skim - not sure alter hook should return $info when it passed by reference, the rest looks nice
Comment #16
jhodgdonGood point! Fixing that.
Comment #17
jhodgdonI added a draft change record for this issue -- a copy-paste of the Release Notes section of the issue summary:
https://www.drupal.org/node/3068527
Code still needs review.
Comment #18
andypostA bit of clean-up, looks default weight always applied
I bet default value will be applied by default
This is only question here, if annotation defines default value (0) then this definition should always contain value.
Also it could be added to list above like `'#weight' => $plugin_definition['weight']`
Should be "protected" and could use @inheritdoc
missing @var
Comment #19
jhodgdoninterdiff looks good to me, assuming tests still pass, thanks!
Comment #20
jhodgdonSo... I am happy with the changes in #18 and +1 for RTBC. @andypost what are your thoughts?
Comment #21
andypostLast patch is mine, but I'd like rtbc)
Comment #22
jhodgdonWell, it looks like you like what I did on the patch, and I like what you did, so I think we both agree it should be RTBC. I'll go ahead and mark it RTBC but if anyone else wants to review, that would be good too.
Comment #23
amber himes matzI'm currently reviewing. Is this patch supposed to move the "Module overviews" section to the end? (So sections are ordered Help Topics, Tours, Module Overviews?)
Comment #24
jhodgdonNo, the plan was to make it Help Topics, Module Overviews, Tours. At least for now... Do you think we should change the order?
Comment #25
amber himes matzI think the order is fine as-is. I got thrown off when reading help.api.php (which is just showing documentation for how a developer could alter the weight). And also, just noticed that the tests are looking for module overviews before tours.
This looks good to me. +1 to RTBC.
Comment #26
jhodgdonGreat, thanks for the review!
The other one that is a blocker for beta for Help Topics is #3067943: Add capability for search blocks on non-default search... :)
Comment #27
amber himes matzDo you think we should add a weight to the HookHelpSection as well? (As with TourHelpSection?)
I was thinking this might help someone looking at help.api.php's hook_help_section_alter connect
$info['hook_help']['weight']with the weight in the annotation. Perhaps, too, we should add a comment for @HelpSection annotations about hook_help_section_alter?Comment #28
jhodgdonI had a weight of 0 in there originally, but andypost thought we should take it out and let it default to 0 on an earlier review, so I did that.
As far as documenting the hook... The hook existed prior to this patch, and when it was created, we followed the general practice for this type of hook (altering plugin definitions). So it is linked from where the hook is invoked, which is on the plugin manager class:
https://api.drupal.org/api/drupal/core%21modules%21help%21src%21HelpSect...
Comment #29
larowlanissue credits for @Amber's review
Comment #30
larowlannice work folks 🎉
Committed 973da43 and pushed to 8.8.x. Thanks!