Skip to content
Snippets Groups Projects

3468180: Fix undefined array key 'view_mode' when a custom block renders a block_content directly

Closed Eric Volkernick requested to merge issue/drupal-3468180:3468180-undefined-view-mode into 11.x

3468180: Fix issue where we receive warning for undefined array key 'view_mode' when a custom block renders a block_content directly.

Since we are already looking to $variables['elements']['content'] for #block_content, we might as well get the #view_mode there too.

Closes #3468180

Merge request reports

Closed by Théodore BiadalaThéodore Biadala 1 month ago (Apr 18, 2025 8:48am UTC)

Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
119 119 $block_content = $variables['elements']['content']['#block_content'] ?? NULL;
120 120 if ($block_content instanceof BlockContentInterface) {
121 121 $bundle = $content['#block_content']->bundle();
122 $view_mode = strtr($variables['elements']['#configuration']['view_mode'], '.', '_');
122 $view_mode = strtr($variables['elements']['content']['#view_mode'], '.', '_');
  • If we have previous place where view_mode is store, why not to have a backward compatibility?

    Suggested change
    122 $view_mode = strtr($variables['elements']['content']['#view_mode'], '.', '_');
    122 $configuration_view_mode = $variables['elements']['#configuration']['view_mode'] ?? null;
    123 $content_view_mode = $variables['elements']['content']['#view_mode'] ?? null;
    124 $view_mode = strtr($configuration_view_mode ?? $content_view_mode;, '.', '_');
  • Because that is not DRY if the view mode is always in the content anyway. Do you have a use case where the view mode is in configuration and not content?

  • john.oltman changed this line in version 18 of the diff

    changed this line in version 18 of the diff

  • Please register or sign in to reply
  • john.oltman added 23 commits

    added 23 commits

    Compare with previous version

  • john.oltman added 1 commit

    added 1 commit

    Compare with previous version

  • john.oltman added 1 commit

    added 1 commit

    Compare with previous version

  • john.oltman added 1 commit

    added 1 commit

    Compare with previous version

  • john.oltman added 1 commit

    added 1 commit

    Compare with previous version

  • john.oltman added 1 commit

    added 1 commit

    Compare with previous version

  • john.oltman added 1 commit

    added 1 commit

    Compare with previous version

  • john.oltman added 1 commit

    added 1 commit

    Compare with previous version

  • john.oltman added 1 commit

    added 1 commit

    Compare with previous version

  • john.oltman added 1 commit

    added 1 commit

    Compare with previous version

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading