BlockViewBuilder does not respect the view mode

Created on 22 April 2016, over 8 years ago
Updated 26 May 2023, over 1 year ago

Problem/Motivation

  public static function lazyBuilder($entity_id, $view_mode) {
    return static::buildPreRenderableBlock(entity_load('block', $entity_id), \Drupal::service('module_handler'));
  }

The $view_mode parameter is ignored. Doing something like
\Drupal::entityTypeManager()->getViewBuilder('block')->view($block, 'custom_view_mode');
results in the block being displayed in the 'default' view mode and not 'custom_view_mode'.

I'm not familiar enough with the D8 block systems but it seems it's due to the fact that regular block does not have view modes. The 'block_content' or custom blocks however does (the viewbuilder is quite different in that case).

So I don't know if the parameter should be removed or used ? My use case was making a custom block by extending BlockBase since this block would return always the same content (via the build method). and then having multiple view mode for this block (to get multiples templates).

Proposed resolution

???

Remaining tasks

Not clear.

User interface changes

NONE

API changes

Maybe ?

Data model changes

NONE

πŸ› Bug report
Status

Closed: works as designed

Version

9.5

Component
BlockΒ  β†’

Last updated 3 days ago

Created by

πŸ‡«πŸ‡·France morsok Paris

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024