Do not load twice the embedded view

Created on 19 March 2024, 3 months ago
Updated 28 March 2024, 3 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

Needs review

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.69.0 2024