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->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->getEntity();<br>if (!$entity->isNew()) {<br> $selection_settings['entity'] = $entity;<br>}</pre><p>Element (EntityAutocompleteTagify) - same as EntityAutocomplete:</p>
<pre>if (isset($selection_settings['entity']) && ($selection_settings['entity'] instanceof EntityInterface)) {<br> $autocomplete_query_parameters['entity_type'] = $selection_settings['entity']->getEntityTypeId();<br> $autocomplete_query_parameters['entity_id'] = $selection_settings['entity']->id();<br> unset($selection_settings['entity']);<br>}</pre><p>Controller (TagifyEntityAutocompleteController) - same as EntityAutocompleteController:</p>
<pre>$entity_type_id = $request->query->get('entity_type');<br>if ($entity_type_id && $this->entityTypeManager->hasDefinition($entity_type_id)) {<br> $entity_id = $request->query->get('entity_id');<br> if ($entity_id) {<br> $entity = $this->entityTypeManager->getStorage($entity_type_id)->load($entity_id);<br> if ($entity && $entity->access('update')) {<br> $selection_settings['entity'] = $entity;<br> }<br> }<br>}</pre><p>All three changes directly mirror core's entity reference autocomplete implementation.</p>
issue