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.

CommentFileSizeAuthor
blockgroup-7.x-1.x-features-revert-bug.diff524 bytesmaijs

Comments

kerby70’s picture

+1 thanks.

  • znerol committed b44f5ee on 7.x-1.x authored by maijs
    Issue #2189393 by maijs: Fix Blockgroup settings in features are not...
  • znerol committed 38e8739 on 7.x-2.x authored by maijs
    Issue #2189393 by maijs: Fix Blockgroup settings in features are not...
znerol’s picture

Status: Needs review » Fixed

Thank you.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.