Tagify widget doesn't pass entity context to selection handlers
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3569441. --> Reported by: [loze](https://www.drupal.org/user/116906) Related to !196 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>Tagify's autocomplete doesn't pass the host entity to selection handlers, breaking any handler that relies on <code>$this-&gt;configuration['entity']</code>.</p> <p>Default selection handlers (<code>default:node</code>, <code>default:taxonomy_term</code>, etc.) don't use entity context, so this issue only surfaces with custom or contrib selection handlers that need the host entity for access checks or filtering.</p> <h4>Core's approach</h4> <p>Core's <code>entity_reference_autocomplete</code> widget handles this in three places:</p> <ul> <li>Widget (<code>EntityReferenceAutocompleteWidget::formElement()</code>) - adds entity to selection_settings</li> <li>Element (<code>EntityAutocomplete::processEntityAutocomplete()</code>) - extracts to entity_type/entity_id query params</li> <li>Controller (<code>EntityAutocompleteController::handleAutocomplete()</code>) - loads entity from query params</li> </ul> <p>Tagify should do the same but is missing all three steps.</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>Match core's <code>entity_reference_autocomplete</code> implementation:</p> <p>Widget (TagifyEntityReferenceAutocompleteWidget) - same as EntityReferenceAutocompleteWidget:</p> <pre>$entity = $items-&gt;getEntity();<br>if (!$entity-&gt;isNew()) {<br>&nbsp; $selection_settings['entity'] = $entity;<br>}</pre><p>Element (EntityAutocompleteTagify) - same as EntityAutocomplete:</p> <pre>if (isset($selection_settings['entity']) &amp;&amp; ($selection_settings['entity'] instanceof EntityInterface)) {<br>&nbsp; $autocomplete_query_parameters['entity_type'] = $selection_settings['entity']-&gt;getEntityTypeId();<br>&nbsp; $autocomplete_query_parameters['entity_id'] = $selection_settings['entity']-&gt;id();<br>&nbsp; unset($selection_settings['entity']);<br>}</pre><p>Controller (TagifyEntityAutocompleteController) - same as EntityAutocompleteController:</p> <pre>$entity_type_id = $request-&gt;query-&gt;get('entity_type');<br>if ($entity_type_id &amp;&amp; $this-&gt;entityTypeManager-&gt;hasDefinition($entity_type_id)) {<br>&nbsp; $entity_id = $request-&gt;query-&gt;get('entity_id');<br>&nbsp; if ($entity_id) {<br>&nbsp;&nbsp;&nbsp; $entity = $this-&gt;entityTypeManager-&gt;getStorage($entity_type_id)-&gt;load($entity_id);<br>&nbsp;&nbsp;&nbsp; if ($entity &amp;&amp; $entity-&gt;access('update')) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $selection_settings['entity'] = $entity;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; }<br>}</pre><p>All three changes directly mirror core's entity reference autocomplete implementation.</p>
issue