Spin-off from #1649780: Remove first/last/odd/even classes in favor of CSS3 pseudo selectors. That issue has a lot of support from people in principle, but still needs to work through some details for tables. Meanwhile, for #1927608: Remove the tight coupling between Block Plugins and Block Entities and cacheability of blocks, we need to decouple the markup produced by a block from its rendering context (i.e., region and position).
So, here's a hopefully uncontroversial small patch to make incremental progress. It removes the positional variables ($id (which despite the name is only a position counter, not an id) and $zebra) provided to all templates and the block-specific ones ($block_id (also only a position counter) and $block_zebra) provided to block.tpl.php. Core does not use these variables anyway (none of the core templates print them, they're only mentioned in the template documentation, and even there, only for block, node, and taxonomy-term, even though the variables are provided to all templates), and per #1649780: Remove first/last/odd/even classes in favor of CSS3 pseudo selectors, D8 contrib shouldn't use these variables either, since CSS3 is the better way.
This patch doesn't change the behavior of theme_item_list(), theme_table(), and similar functions that work on arrays and output zebra classes. That remains a job for #1649780: Remove first/last/odd/even classes in favor of CSS3 pseudo selectors or another spin-off. This patch is only about removing position/zebra handling from templates that work on single objects and rely on the theme system to track position based on invocation order.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | Screenshot_4_12_13_11_41_AM-2.png | 49.29 KB | jessebeach |
| remove-template-zebra.patch | 6.23 KB | effulgentsia |
Comments
Comment #1
effulgentsia commentedtagging
Comment #2
eclipsegc commentedI suppose we're waiting for front-ender feedback? I see no reason not to rtbc this patch in its current form.
Eclipse
Comment #3
jessebeach commentedZebra striping on blocks is an anachronism from a more civilized past. It's time to let it go. We can achieve this effect with CSS.
And this is just bizarre:
A random id is not the solid ground you want to build your styling on. I think these IDs were intended to provide hooks for styling that we can now emulate with CSS
:nth-childselectors.+1 for patches that remove more code than they introduce!
Here's an image of what we're removing (the code shown in the image is given below it. The data- attributes provide examples of the data that will be removed).
Comment #4
effulgentsia commented@jessebeach: what theme is that from? I wasn't aware that any core theme / module even added those data- attributes.
Comment #5
jessebeach commentedOh, sorry. They're not in any core code. I just added them to illustrate what it is that we're removing.
Comment #6
nod_+1
Comment #7
lewisnymanThe thing is, you can achieve this using nth-child. But that's not supported in ie8. So we could be leaving some % of people in the cold by removing those 'odd even' classes. And you can't say its always going to be purely aesthetic like rounded corners.
How hard would it be for a someone to add these classes back in?
Comment #8
eclipsegc commentedIt'd probably be a bit of a pain, but I think we have to accept a "progressive enhancement" approach here. It's basically the only sane way to handle IE anymore, and I think that's a pretty realistic expectation for front-enders.
No?
Eclipse
Comment #9
effulgentsia commentedThe thing is these classes are incompatible with block and entity render caching, so once we turn those on by default in D8, a contrib module will only be able to add them back in by also turning those caches off. IMO, a better solution for someone who wants to zebra stripe blocks and entities in IE8 is to add http://selectivizr.com/ or something like that. Then the only site visitors who don't get to see zebra stripes are IE8 visitors with JS disabled, and that's a very small population, and they can still use the site, just without seeing zebra styling.
Comment #10
jessebeach commentedLewis, it's a fair point. One could get the odd/even classes by using JavaScript. Something like this.
Comment #11
oresh commentedThats a nice js solution. As a front end tell you: usage of odd/even property on everything except views-row and tables is a very rare occasion. The same fir id - its so random, that its really hard to control.
Most of the site use panels or custom block classes or theme with own regions etc. So I see no need in those things.
I wish drupal 8 didn't support ie8 nativly, but had a module which added support for ie7-8 in core.
Comment #12
dvessel commentedI can get behind this. They really are not needed and the minimal amount of php to recreate it can be done by anyone if needed.
Comment #13
chrisjlee commented+1
Comment #14
mortendk commented+1 lets us do the work with css :)
Comment #15
sunThese overly generic odd/even classes and variables are definitely needless and can be safely removed.
Comment #16
webchickWell, that's a pretty resounding vote for "kill it with fire!" :)
Committed and pushed to 8.x. Thanks!
This'll need a change notice, and it'd be great if the workaround code from #10 makes it in there, because people who really really need their zebra striped blocks fix would be unlikely to find it otherwise.
Comment #17
chrisjlee commented@webchick awesome!
Regarding the follow up code for legacy support in the change notice. I'd like to provide feedback from #10.
@jessebeach:
Would it just be easier and more performant if you used CSS3 selectors for jQuery to manage adding your block classes?
Let me know if I'm missing something or if there's a reason why that wouldn't work:
e.g.
You then call this in your theme and provide it context. E.g.
Or it could you could even go as far as skipping the odd class; since if it's not even it has to be odd:
Comment #18
jessebeach commentedDefinitely. It depends on what your browser support requirements are.
The example code in #10 polyfills the region/block context behavior that this issue removed. It's a way of getting back what was taken. There are certainly more concise ways of writing this code if you don't need, for instance, total block count striping.
Comment #19
chrisjlee commentedOops sorry. accidently removed tag.
@jessebeach oh i see what you're getting at. That's the reason for interating over the rows with $.each() and finding each block / region. I didn't totally understand the reason for doing that at first.
Comment #20
gábor hojtsyAdded change notice at https://drupal.org/node/2011412
Comment #21.0
(not verified) commented.