The $page array is supposed to be a renderable array, and the first level things in it are regions... but the second level is not necessarily blocks... it can be arrays that contain blocks (or really could be any renderable array). bartik_page_alter() makes some pretty inflexible assumptions about this, as discovered in #867256: Create render example demonstrating D7 render arrays and altering. Basically, when bartik_page_alter() is searching for blocks to set block ordering (IMO) it needs to search the region recursively, not just assume a block in the top-level element.

To demonstrate the error, use the patch in #867256: Create render example demonstrating D7 render arrays and altering and enable block array reporting.

Attached is a patch that would be more generous about its approach to the page array.

Comments

Jeff Burnz’s picture

I added the example module and without the patch I get a bunch of notices:

# Notice: Undefined property: stdClass::$position_first in bartik_preprocess_block() (line 112 of C:\Users\Jeff\Documents\Aptana Studio Workspace\d7\drupal\themes\bartik\template.php).
# Notice: Undefined property: stdClass::$position_last in bartik_preprocess_block() (line 115 of C:\Users\Jeff\Documents\Aptana Studio Workspace\d7\drupal\themes\bartik\template.php).
# Notice: Undefined property: stdClass::$position in bartik_preprocess_block() (line 119 of C:\Users\Jeff\Documents\Aptana Studio Workspace\d7\drupal\themes\bartik\template.php).

The page alters appear to working regardless - however after applying the patch http://drupal.org/files/issues/drupal.bartik_page_array_fix.patch the notices go away.

Consider this a friendly bump - certainly like to get some more eyes on this.

moshe weitzman’s picture

Any chance we can just put these classes in for all themes (i.e. move to block module)?

Jeff Burnz’s picture

I looked at this more in Bartik and from what I can tell these classes are not even being used. I suspect they may have been something to do with layout before we remodeled and simplified the entire layout CSS.

Frankly, as a themer, my experience with these first/last classes on blocks is that they sound good to have but in reality you hardly ever use them, as in almost never. Be interested what other themers say about these classes, I personally have not had a use for them in living memory and with modules like Skinr, blockclass and so on its really easy to add classes a specific block if you need it - its just so rare to have any need to style the first and/or last block in a region (layout aside, which can be useful for eliminating padding in grids layouts).

rfay’s picture

Great - let's pull this whole hook_page_alter()!

Jeff Burnz’s picture

Title: bartik_page_alter() makes too many assumptions about structure of $page array » remove bartik_page_alter() and extra block classes
StatusFileSize
new1.78 KB

Agreed.

None of these extra block classes are used by Bartik, and because this is not a starter theme I see little reason why we need to carry this overhead.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

code looks good

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Status: Fixed » Closed (fixed)

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