Block modules uses BLOCK_REGION_NONE to mark blocks which are not in any region. However, this is only used in code, and the actual value in the database used for these blocks is the '' (empty string) region. For example, the dropdowns on the block admin page have -1 (== BLOCK_REGION_NONE) as value to placing blocks in no region. But then in block_admin_display_form_submit(), the block status is set depending on the region placement and then the region is set to an empty string if the status was 0. So basically, -1 region becomes '' for saving to database.

This same process is not happening to the newly added region selector on the block configuration pages themselves. When adding a new block and not selecting a region, the block code for the disabled region uses -1 just like the blocks page. However, when saving, the actual value is used to save the block instead of using the above conversion to ''. This results in the page coming back showing a warning The block %info was assigned to the invalid region %region and has been disabled., which keeps showing for all newly added blocks on the blocks listing interface until that form is submitted, and the database values are cleaned up with the above explained workflow.

Therefore to conform to the existing behavior (and do not introduce any API changes), I propose we fix saving data when the block is added.

This bug was introduced in #503782: Not able to select region at block creation and noted by @Jacob Singh at http://drupal.org/node/544360#comment-2127370 and by @webchick at http://drupal.org/node/517688#comment-2170538

This picture illustrate what shows on the blocks admin page with 4 new (dummy) blocks added until I submit this form to clean up these values. Not nice at all.

Comments

Status: Needs review » Needs work

The last submitted patch failed testing.

pwolanin’s picture

Status: Needs work » Needs review
StatusFileSize
new1.09 KB

patch wasn't rolled from root dir.

dries’s picture

Good catch, but this needs a test IMO -- assuming that there is an obvious test for it.

gábor hojtsy’s picture

We can easily add a test to look whether adding a block and not setting regions triggers this bug or not. Not sure of that test's general applicability though.

dries’s picture

Status: Needs review » Needs work
Issue tags: +Needs work

I committed the patch but I'm leaving this as 'Needs tests' and 'Needs work' so we can follow-up with tests.

benjy’s picture

Status: Needs work » Closed (fixed)

I've had a look at the code and reverting the patch no longer causes the same issue for me. I think we should close this ticket and a new one should be created if we want to develop a specific test for blocks.