I have a blockgroup block that is exported to module mymodule via Features.
The code in mymodule.features.inc:
/**
* Implements hook_default_blockgroups().
*/
function mymodule_default_blockgroups() {
return array(
'myblock' => 'My block',
);
}
The line in mymodule.info:
features[blockgroup][] = myblock
I delete the blockgroup block "My block" in Structure > Block administration page and then try to revert the features in Structure > Features > mymodule.
Expected restults: blockgroup block is recreated.
Actual results: blockgroup block is not recreated.
The problem is in blockgroup_features_rebuild() function. In order to check whether blockgroup block should be added, it loads the block via blockgroup_load() which in turn loads the block via block_load(). Then blockgroup_features_rebuild() checks whether the block exists using if (!$blockgroup) statement. The problem is that if the block does not exist, block_load() returns an object with module and delta properties, therefore if (!$blockgroup) statement does not in fact determine whether block exists or not.
In order to check whether blockgroup block exists, the function should check for existence of bid property.
Code in blockgroup_features_rebuild():
$blockgroup = blockgroup_load($delta);
if (!$blockgroup) {
$blockgroup = (object) array(
'title' => $title,
'delta' => $delta,
);
blockgroup_add($blockgroup);
}
should be:
$blockgroup = blockgroup_load($delta);
// Prepare the block if it doesn't exist
if (!isset($blockgroup->bid)) {
$blockgroup = (object) array(
'title' => $title,
'delta' => $delta,
);
blockgroup_add($blockgroup);
}
The patch provided for 7.x-1.x branch fixes this problem.
| Comment | File | Size | Author |
|---|---|---|---|
| blockgroup-7.x-1.x-features-revert-bug.diff | 524 bytes | maijs |
Comments
Comment #1
kerby70 commented+1 thanks.
Comment #3
znerol commentedThank you.