I attempted to test this module on a vanilla site this morning. The site was on a fresh database with just Session API (w/ patch) and Persona installed.
As admin, I could log out. However, as anonymous, every page results in the following:
Recoverable fatal error: Argument 1 passed to persona_block_view_alter() must be an array, null given, called in /var/www/ptstest1a/drupal/includes/module.inc on line 1063 and defined in persona_block_view_alter() (line 510 of /var/www/ptstest1a/drupal/sites/all/modules/persona/persona.module).
To debug, I altered persona_block_view_alter() to match the following:
/**
* Implements hook_block_view_alter().
*/
function persona_block_view_alter($data, $block) {
if (!$data) {
drupal_set_message('$block is ' . var_export($block, TRUE));
return;
}
if (variable_get('persona_takeover') && $block->module == 'user' && $block->delta == 'login') {
$data['content'] = array();
}
}
This turned up the following two blocks getting passed to the hook_block_alter() with a null $data occasionally:
$block is stdClass::__set_state(array( 'bid' => '2', 'module' => 'search', 'delta' => 'form', 'theme' => 'bartik', 'status' => '1', 'weight' => '-1', 'region' => 'sidebar_first', 'custom' => '0', 'visibility' => '0', 'pages' => '', 'title' => '', 'cache' => '-1', ))
$block is stdClass::__set_state(array( 'bid' => '4', 'module' => 'user', 'delta' => 'login', 'theme' => 'bartik', 'status' => '1', 'weight' => '0', 'region' => 'sidebar_first', 'custom' => '0', 'visibility' => '0', 'pages' => '', 'title' => '', 'cache' => '-1', ))
Theoretically, $data shouldn't ever be null here... but it is in core. The attached patch makes the module handle this situation for now. I'll file a core issue and reference it here as well.
| Comment | File | Size | Author |
|---|---|---|---|
| fix-null--variable.patch | 592 bytes | brianV |
Comments
Comment #1
brianV commentedCore issue created in #1967802: NULL $data variables get sent to hook_block_view_alter() occasionally.
Comment #2
jbrown commentedThanks!
http://drupalcode.org/project/persona.git/commitdiff/5aad7e1
Comment #4
neRok commentedI just closed the core issue referred to in #1. I just had a quick look at the code in the commit in #2. Can I suggest that since you are only modifying 1 block, it may be advantageous to implement the more direct hook_block_view_user_login_alter. The current hook_block_view_alter you are using will check every block, adding a little overhead.
Comment #5
brianV commentedRe-closing this.
@neRok:
Closing the core issue (#1967802: NULL $data variables get sent to hook_block_view_alter() occasionally) was premature on your part. As long as core behaviour and the documentation are inconsistent, there is an issue to be fixed.
Comment #6
neRok commentedAre you sure you want to close this one. My suggestion in #4 is still valid.
Comment #7
brianV commentedneRok:
I did intend to close this, but I should have added a note as to *why* I closed it.
Your idea is a good one, and probably should be fixed in code. That said, it's a separate issue from the one that was reported in the original post, and fixed in the commit reported in #2.
I would open a new issue titled something along the lines of 'Use hook_block_view_user_login_alter() instead of hook_block_view_alter()' with a patch to implement it, and crosslink it here. I'd happily +1 the idea - performance is always good!