Problem/Motivation
It is easy to implement hook_help() incorrectly and cause visual defects in themes like Bartik.
For example, the Redirect module does:
/**
* Implements hook_help().
*/
function redirect_help($route_name, RouteMatchInterface $route_match) {
$output = '';
switch ($route_name) {
case 'redirect.fix_404':
$output = '<p>' . t('This page lists all paths that have resulted in 404 errors and do not yet have any redirects assigned to them.') . '</p>';
break;
}
return $output;
}
This results in a spurious empty block on the page which has a border.
Proposed resolution
Treat an empty string the same as a NULL.
Remaining tasks
User interface changes
None
API changes
Just an API tweek - treat an empty string the same as a NULL.
Data model changes
None
Comments
Comment #2
alexpottActually this is a regression from Drupal 7. Here is the code that gets the help for a path...
So if hook returns an empty string it won't be added to the $output...
if ($help = $function($router_path, $arg)) {.I think it is worth fixing this behaviour in Drupal 8 as the current behaviour in HEAD if very unexpected.
Comment #3
alexpottComment #4
alexpottHere's a test that shows the problem.
Comment #6
jhodgdonThis entire test and patch looks great, except ...
What is this function? Maybe it was some debugging code you left in by mistake?
Comment #7
alexpott@jhodgdon lol yep :)
Comment #8
dave reidMinor but not needed to reassign $item? This also feels like it reads cleaner:
$build[] = is_array($item) ? $item : ['#markup' => $item];
Comment #9
alexpottMaybe this approach is slightly neater...
Comment #10
alexpottSo actually given https://www.drupal.org/core/d8-bc-policy#plugins let's go a little bit further and clean up the block plugin to be a little easier to understand. I implemented #8 too.
There is a further issue to address. I think hook_help is making incorrect assumptions about how module invoke all works because I don't think the is_array() is working as expected. But this is the stuff of followups.
Comment #11
alexpottI'm tagging this as a contributed project blocker because the behaviour change between d7 and d8 is subtle and easy to miss and I'm not sure we want to file issues like #2707105: Redirect's hook_help returns an empty string on all calls against all contrib... the pattern of setting $output = ''; and returning it is really common. So common I think it is worth discussing this as a potential rc target because 6 months waiting for this fix feels like a long time.
Comment #12
jhodgdonI completely agree this is a non-disruptive change -- it is changing the API behavior to be what everyone would expect it to be, not to mention what it was in D7.
Fixed the title, which had gotten reversed from what it should have been.
The patch looks great, except for a number of comment nitpicks:
nitpick: needs to end in .
nitpick: Log in is a verb; login is a noun/adjective.
This comment is also not accurate. We're not using the root user (which would be user 1), but an admin user created in the setUp() method.
nitpick: this should end in .
Comment #13
alexpottFixed on the review points from #12 - funnily enough there's no need to log in at all so just removed all of that.
Comment #14
jhodgdonYeah, the test module gives TRUE as access to those pages. Much cleaner.
So I think this is ready to go, assuming the test bot agrees on the latest patch. Would it make sense to upload a test-only patch just to make sure it still fails in its current lean-and-mean state? I think it would... so here is one (I just edited the patch file from #13 and took out the HelpBlock portion).
Assuming this one fails, and the one in #13 passes, we're good to go. Hopefully having this patch here will not cause the test bot to test it over and over and set the issue to Needs Work.
Comment #15
alexpottYeah it will cause the bot to have fun with the issue so re-uploading #13
Comment #17
xjmSo this is not really a contributed project blocker because it can be worked around by returning
NULL. I'd call it major though because of the unexpected visual regressions.Comment #18
alexpottThe reason I added "contributed project blocker" is that the pattern of returning an empty string worked in D7 and it is super super easy to miss that your module is causes this visual issue and there is not much a site owner can do if they want to have the help module enabled.
Comment #20
catchMakes sense to do this in RC - it's user-facing and at least with the current patch can't be fixed in a patch release.
Committed/pushed to 8.2.x and cherry-picked to 8.1.x. Thanks!