API page: https://api.drupal.org/api/drupal/modules%21block%21block.api.php/functi...
Enter a descriptive title (above) relating to function hook_block_view, then describe the problem you have found:
Blocks are sometimes empty depending on circumstances. A good example in core is the user login block, in https://api.drupal.org/api/drupal/modules!user!user.module/function/user...
case 'login':
// For usability's sake, avoid showing two login forms on one page.
if (!$user->uid && !(arg(0) == 'user' && !is_numeric(arg(1)))) {
$block['subject'] = t('User login');
$block['content'] = drupal_get_form('user_login_block');
}
return $block;
This clearly shows it's ok to return an empty array.
However, hook_block_view() doesn't document this possibility.
Comments
Comment #1
jhodgdonGood catch! Maybe it should also mention that if $block['content'] is empty, the block is not shown at all (even the title) -- at least I think that is the case?
Comment #2
alexandre.todorov CreditAttribution: alexandre.todorov commentedHere is a patch about :
Comment #3
DuaelFrRemoving forgotten assignation
Comment #4
jhodgdonThanks! This needs a little bit of adjustment though:
Can we put the last sentence before the list instead of after? Also, for formatting: The new text needs to be wrapped with the previous sentence into lines that go as close to 80 characters as possible without going over. And "The" should not be capitalized.
Comment #5
skipyT CreditAttribution: skipyT commentedModified the documentation, please check again.
Comment #6
jhodgdonThanks!
The first line of the @return still needs some work:
It really should just start with "Either an empty array..." not "May be an empty array...". And please change "so as the block is not shown at all" to "(the block will not be shown),".
Comment #7
skipyT CreditAttribution: skipyT commentedI rephrased the first line and also the last one with the empty content.
Comment #8
skipyT CreditAttribution: skipyT commentedThe patch file's name was incorrect. Renamed it.
Comment #9
jhodgdonThank you! That is very clear, and I think this is ready to go.
Comment #10
jhodgdonThanks all! Committed to 7.x.