Do not load twice the embedded view

Created on 19 March 2024, 8 months ago
Updated 4 July 2024, 4 months ago

FieldEmbedView::getFieldBuild() contains the following code.

      $view = Views::getView($display_field['settings']['embed_view']);
      $view->setDisplay($display_settings['settings']['view_display'] ?? 'default');

      $view->setAjaxEnabled($display_settings['settings']['enable_ajax'] ?? 'default');

      // Set the view URL to the current page for the exposed filter form
      // redirection.
      $view->override_url = Url::fromRoute('<current>');

      // Build the view arguments.
      $args = [];
      if (!empty($display_settings['settings']['arguments'])) {
        $view_object = \Drupal::service('entity_type.manager')->getStorage('view')->load($display_field['settings']['embed_view']);

        // Omissis

      }

The code is loading the same view twice, first via Views::getView() and then via \Drupal::service('entity_type.manager')->getStorage('view')->load() which would return the same value, since Views::getView() contains the following code.

  $view = \Drupal::entityTypeManager()
    ->getStorage('view')
    ->load($id);
  if ($view) {
    return static::executableFactory()
      ->get($view);
  }
  return NULL;
📌 Task
Status

Fixed

Version

9.1

Component

Code

Created by

🇮🇹Italy apaderno Brescia, 🇮🇹

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024