Warning for missing view/display

Created on 24 May 2025, 7 days ago

File: "C:\Websteder\D10\pkt10.cbmsupport\pkt10\pkt\core\modules\views\src\Plugin\EntityReferenceSelection\ViewsSelection.php"

Function initializeView()

When a view is not found it returns the warning "The reference view %view_name cannot be found."

BUT:
If a display in a view is not found, it returns the same warning.
I think it should return something like "In the view %view_name the display %display_name cannot be found."

Existing code:

    if (!$this->view || !$this->view->access($display_name)) {
      \Drupal::messenger()->addWarning($this->t('The reference view %view_name cannot be found.', ['%view_name' => $view_name]));
      return FALSE;
    }

Proposal for modified code:

    if (!$this->view || !$this->view->access($display_name)) {
      if(!$this->view){
        \Drupal::messenger()->addWarning($this->t('The reference view %view_name cannot be found.', ['%view_name' => $view_name]));
      }elseif(!$this->view->access($display_name)){
        \Drupal::messenger()->addWarning($this->t('In the reference view "%view_name", the display "%display_name" cannot be found.', ['%view_name' => $view_name, '%display_name' => $display_name]));
      }
      return FALSE;
    }

My "new" code is tested and is working

✨ Feature request
Status

Active

Version

10.5 ✨

Component

views.module

Created by

šŸ‡©šŸ‡°Denmark uv516 Denmark

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

Merge Requests

Comments & Activities

  • Issue created by @uv516
  • šŸ‡©šŸ‡°Denmark uv516 Denmark
  • šŸ‡®šŸ‡³India libbna New Delhi, India

    Hi @uv516, before I start working on this, I’d like to confirm the steps to reproduce the issue. Once I make the necessary changes, I want to ensure I can verify whether the issue is resolved. Could you please share the exact steps to reproduce the issue?

  • šŸ‡®šŸ‡³India libbna New Delhi, India
  • šŸ‡©šŸ‡°Denmark uv516 Denmark

    It's fairly basic:
    When a reference field has been created, a views reference with an associated display name must be used.
    The view's machine name is unique and the display name is unique (machine names).
    You create a view with an entity reference that can display results for an entity reference field.
    If the view disappears for some reason or the machine name is changed, "our function" will display the error text "The reference view %view_name cannot be found". That's ok.
    If the display (in the view) is deleted for some reason or (NOTE:) the display's machine name is changed, exactly the same error is displayed: "The reference view %view_name cannot be found". The problem is that it's actually not the right error. The view exists! and the view can be found, but it's the display's machine name that can't be found. The error text doesn't point to the actual error, but to the (existing) view that contains the display.
    The code uses "!$this->view", which refers to whether the parent view exists. The code !$this->view->access($display_name) refers to whether the display is accessible with $display_name. So two different errors with the same error text.
    In my proposal, I distinguish between the two error types, simply because I thought that my display should have a different machine name, which is why I changed the display's machine name. The result was that my reference field could not find the display even though it found the view.
    For a long time I was surprised that I was told that the view could not be found, when it was there, and only after a while did I find out that it was actually the display that was "missing" (= had been given a different machine name). Therefore, it would have saved me a few hours of searching if the error text had immediately led me to the conclusion that it was the display that could not be found and that I could thus quickly correct the machine name back to the original one (or change the reference field).
    My proposal is simply to create one error text for the missing view and another error text for the missing display (inside the view).
    Therefore: If a display cannot be "seen" by the reference field, the error message "In the reference view "%view_name", the display "%display_name" cannot be found." will appear. This will tell the programmer that there is an error in the existing view with the display %display_name.

  • šŸ‡©šŸ‡°Denmark uv516 Denmark
    1. Create a view
    2. Create a display (entity reference). (The machine name i automatic given.)
    3. Create a field of entity reference and referending to the view and display. (OK!)
    4. Change the machine name of the display. (Now i get the error "The reference view %view_name cannot be found.", but the view CAN be found, so the error message is confusing.)
    5. I am using a lot of time to search the error in different ways.
    6. I found that the displays machine name should not have been changed. I renamed it to the original name (+flush...)
    7. Now my reference filed again could see the view and the display.

    I f I've godt "my" errortext "In the reference view "%view_name", the display "%display_name" cannot be found.", I would have saved a lot of time troubleshooting.

  • šŸ‡®šŸ‡³India libbna New Delhi, India

    Understood. Thanks @uv516 for all the information. I will raise the MR for this today.

  • Merge request !122353526426-warning-for-missing → (Closed) created by libbna
  • Pipeline finished with Failed
    5 days ago
    Total: 245s
    #506501
  • Merge request !12236updated the code for view display error → (Open) created by libbna
  • šŸ‡®šŸ‡³India libbna New Delhi, India

    I encountered some issues with the original branch, so I decided to close it. I have now created a new branch, updated the base branch to 10.5, and pushed the changes accordingly as suggested.

    Changing the status to needs review.

  • Pipeline finished with Failed
    5 days ago
    #506535
  • šŸ‡ŗšŸ‡øUnited States smustgrave

    MRs should be pointed at 11.x and will need test coverage.

    Also issue summary template appears to be missing.

  • šŸ‡®šŸ‡³India libbna New Delhi, India

    @smustgrave should I create a new MR for 11.x.dev or should I update branch of the current MR?

  • First try updating the target branch.

  • šŸ‡®šŸ‡³India libbna New Delhi, India

    I attempted to update the target branch of the merge request, but it appears to be causing issues — the changes are not reflecting correctly. I believe the best course of action is to create a new branch based on 11.x and open a fresh merge request.

Production build 0.71.5 2024