Improve blazy_blazy_settings_alter for rendered entities within a view

Created on 18 March 2021, about 4 years ago
Updated 16 May 2023, almost 2 years ago

Problem/Motivation

The blazy module's implementation of hook_blazy_settings_alter() incorrectly assumes that every blazy rendering while a Views view is executing should have the current view mode set to the View's display id.
Example: A view can be configured to render nodes in a selected view mode, and any image or media fields on the node should render the blazy formatters in the view mode for that entity display config, not the view's display id.

Method in "\Drupal\blazy\BlazyAlter":

/**
   * Implements hook_blazy_settings_alter().
   */
  public static function blazySettingsAlter(array &$build, $items) {
    $settings = &$build['settings'];

    // Sniffs for Views to allow block__no_wrapper, views_no_wrapper, etc.
    if (function_exists('views_get_current_view') && $view = views_get_current_view()) {
      $settings['view_name'] = $view->storage->id();
      $settings['current_view_mode'] = $view->current_display;
      $settings['view_plugin_id'] = empty($settings['view_plugin_id']) ? $view->style_plugin->getPluginId() : $settings['view_plugin_id'];
    }
  }

Steps to reproduce

Build a page with a view that using a "Rendered entity" field in a specific view mode.

Proposed resolution

Remove blazy_blazy_settings_alter()
OR
Determine a better way to set the 'current_view_mode' when rendering a single views field with a blazy formatter.

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇺🇸United States recrit

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