Encountering error when passing query parameter to Entity Reference View

Created on 11 December 2024, 7 days ago

Problem/Motivation

When attempting to create a new, or edit an existing, node to which a query parameter is passed via the URL (i.e., my.website/node/1462/edit?id=12) that has an ER field filtered by an Entity Reference View, an error occurs.

Dblog registers two PHP Warnings and 1 PHP Error, as follows:

  1. Warning: Undefined array key "#row" in Drupal\views\Plugin\EntityReferenceSelection\ViewsSelection->stripAdminAndAnchorTagsFromResults()
  2. Warning: Attempt to read property "_entity" on null in Drupal\views\Plugin\EntityReferenceSelection\ViewsSelection->stripAdminAndAnchorTagsFromResults()
  3. Error: Call to a member function bundle() on null in Drupal\views\Plugin\EntityReferenceSelection\ViewsSelection->stripAdminAndAnchorTagsFromResults()

This problem occurred after upgrading from 2.0.8 to 2.0.9. When the query parameter is removed from the URL, the page loads, but (obviously) without the filtered ER options.

Steps to reproduce

  1. Create a content type that has an ER field that uses the View ER method.
  2. Create an Entity Reference View with a contextual filter that uses the "Query Parameter" for default value
  3. Create an "edit" link and/or a "create" link that includes the parameter such as "?id=12"
  4. Attempt to edit or create a node of the said content type ... this is where the error occurs.

Note, the query parameter being passed is the ID of a "group" defined by the Group Module. The problem does not appear to be a Group Module issue, but could be.

Besides the fact that this problem only occurs when updating the ECA Module from 2.0.8 > 2.0.9, it appears this problem could be related to a certain issue addressed by the 2.0.9 update, namely:

Proposed resolution

In case it helps, here is a message the OpenAI Log analyzer offers to the initial PHP Warning (Undefined array key "#row"):

The error message indicates that the code is trying to access an array key "#row" that does not exist in the context where it's being used. This is happening in the `stripAdminAndAnchorTagsFromResults()` method of the `ViewsSelection` class in the Views module.

To fix this error, it's necessary to ensure that the array key "#row" is defined before it's being accessed. This can be done by adding a check to see if the key exists in the array before trying to use it.

In the `stripAdminAndAnchorTagsFromResults()` method, find the line where "#row" is being accessed. Before this line, add a check using `isset()` or `array_key_exists()` to see if "#row" is set. If it's not set, you can then define it or handle the situation in a way that makes sense for your specific use case.

I am happy to provide more details.

As an aside, I tried to replicate this problem using Simplytest.me, but ECA does not appear as an available project for evaluation. Maybe there is a more current test site? Please advise.

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States mmlmitchell Spokane, WA

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

Comments & Activities

  • Issue created by @mmlmitchell
  • πŸ‡ΊπŸ‡ΈUnited States mmlmitchell Spokane, WA
  • This also gave my site the touch of death. I had to roll back to 2.0.8. I am experiencing the same errors.

    On my site this happens when I try to create or edit a node which uses an entity reference on a field. The entity reference uses a contextual filter to check against the logged in user.

    When this field with the entity reference is set to "checkboxes" or "select list" and a node with the field is created or edited, the error is produced. If I set the field to auto-complete, I am able to add or edit nodes, but the auto-complete does not work.

    My errors:
    1. Error: Call to a member function bundle() on null in Drupal\views\Plugin\EntityReferenceSelection\ViewsSelection->stripAdminAndAnchorTagsFromResults() (line 289 of /var/www/html/website/web/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php).
    2. Warning: Attempt to read property "_entity" on null in Drupal\views\Plugin\EntityReferenceSelection\ViewsSelection->stripAdminAndAnchorTagsFromResults() (line 288 of /var/www/html/website/web/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php)
    3. Warning: Undefined array key "#row" in Drupal\views\Plugin\EntityReferenceSelection\ViewsSelection->stripAdminAndAnchorTagsFromResults() (line 288 of /var/www/html/website/web/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php)

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    This sounds like related to πŸ› Views Post Render event may break entity reference views Active which is supposed to be fixed. Any chance that one of you could provide me with a reproducable example?

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Oh wait, I've just checked the backport from the related issue and noticed, that this only worked in parts and "forgot" to remove one redundant line in the code.

    Please give this patch a try and let us know if that fixes it for you.

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    We ran into this on other sites too and were able to confirm, that the patches fixes the issue. Published 2.0.10 containing that fix.

Production build 0.71.5 2024