Encountering error when passing query parameter to Entity Reference View
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3493370. -->
Reported by: [mmlmitchell](https://www.drupal.org/user/222839)
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>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.</p>
<p>Dblog registers two PHP Warnings and 1 PHP Error, as follows:</p>
<ol>
<li>Warning: Undefined array key "#row" in Drupal\views\Plugin\EntityReferenceSelection\ViewsSelection->stripAdminAndAnchorTagsFromResults()</li>
<li>Warning: Attempt to read property "_entity" on null in Drupal\views\Plugin\EntityReferenceSelection\ViewsSelection->stripAdminAndAnchorTagsFromResults()</li>
<li>Error: Call to a member function bundle() on null in Drupal\views\Plugin\EntityReferenceSelection\ViewsSelection->stripAdminAndAnchorTagsFromResults()</li>
</ol>
<p>This problem occurrs 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.</p>
<h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<ol>
<li>Create a content type that has an ER field that uses the View ER method. </li>
<li>Create an Entity Reference View with a contextual filter that uses the "Query Parameter" for default value
</li><li>Create an "edit" link and/or a "create" link that includes the parameter such as "?id=12"
</li><li>Attempt to edit or create a node of the said content type ... this is where the error occurs.
</li></ol>
<p>Note, the query parameter being passed in my use case 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 to 2.0.9, it appears this problem could be related to a certain issue addressed by the 2.0.9 update, namely:</p>
<ul>
<li><a href="https://www.drupal.org/project/eca/issues/3492460">3492460: Views Post Render event may break entity reference views</a></li>
</ul>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>In case it helps, here is a message the OpenAI Log Analyzer offers to the initial PHP Warning (Undefined array key "#row"):</p>
<blockquote><p>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.</p>
<p>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.</p>
<p>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.</p></blockquote>
<p>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? I am happy to provide more details. Please advise.</p>
issue