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 for bundle and view_mode.
  • In the block.html.twig template, add classes for bundle (type) and view mode parallel to those added for nodes in node.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.

CommentFileSizeAuthor
#2 at-block-classes-2830412-2.patch1.88 KBnedjo

Comments

nedjo created an issue. See original summary.

nedjo’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new1.88 KB

Patch attached.

nedjo’s picture

Issue summary: View changes
Jeff Burnz’s picture

Category: Feature request » Task

Yep, lets do it, good for consistency.

nedjo’s picture

  • Jeff Burnz committed 87be4a2 on 8.x-1.x authored by nedjo
    Issue #2830412 by nedjo: Add block classes for bundle and view mode
    
Jeff Burnz’s picture

Status: Needs review » Fixed

Good stuff, thanks for the patch nedjo!

Status: Fixed » Closed (fixed)

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