Problem/Motivation
While, for example, nodes are rendered with classes to target theming by node type (bundle) and view mode, core - and, thus far - adaptivetheme - doesn't provide anything parallel for blocks.
Maybe this reflects the hybrid nature of blocks. The block content entity type that supports bundles and view modes is only one of many types of blocks. Whatever the source of this issue, the lack of classes is a barrier when theming custom blocks.
Proposed resolution
- Extend the existing
at_core_preprocess_block()preprocessor to conditionally set variables forbundleandview_mode. - In the
block.html.twigtemplate, add classes for bundle (type) and view mode parallel to those added for nodes innode.html.twig.
Remaining tasks
User interface changes
API changes
Data model changes
Blocks are rendered with classes in the form block--type-image-[bundle] and block--view-mode-[view_mode] where [bundle] and [view_mode] are the bundle name and view mode name, both rendered with hyphens in the place of underscores. Example with bundle of image_link and view mode of full: block--type-image-link and block--view-mode-full.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | at-block-classes-2830412-2.patch | 1.88 KB | nedjo |
Comments
Comment #2
nedjoPatch attached.
Comment #3
nedjoComment #4
Jeff Burnz commentedYep, lets do it, good for consistency.
Comment #5
nedjoComment #7
Jeff Burnz commentedGood stuff, thanks for the patch nedjo!