Problem/Motivation

A selection handler cannot see the entity being edited. Excluding the entity from its own suggestions, or narrowing the matches by something on the entity, has nothing to work from: the selection settings the autocomplete route receives carry no entity.

Steps to reproduce

  1. Put a break in a selection handler while the Autocomplete Deluxe widget is configured.
  2. Type in the field and look at the selection settings.

Proposed resolution

Send the entity type and id with the autocomplete request, and load the entity into the selection settings on the controller, only when it loads and the user may view it. The element also carries the entity in its selection settings, so validation sees it too. The hashed settings and the key value store keep leaving the entity out, so one field keeps one key.

The edit form of a node titled Alpha, with Alpha left out of the suggestions

Remaining tasks

  • ✅ File an issue
  • ✅ Addition/Change/Update/Fix
  • ✅ Testing to ensure no regression
  • ➖ Automated unit testing coverage
  • ➖ Automated functional testing coverage
  • ➖ UX/UI designer responsibilities
  • ➖ Readability
  • ➖ Accessibility
  • ➖ Performance
  • ✅ Security
  • ➖ Developer Documentation
  • ➖ User Guide Documentation
  • ➖ Reviewed by human
  • ➖ Code review by maintainers
  • ➖ Full testing and approval
  • ➖ Credit contributors
  • ➖ Review with the product owner
  • ➖ Release notes snippet
  • ❌ Release

User interface changes

  • N/A

API changes

  • A selection handler receives the entity being edited in its settings under entity, when there is one.

Data model changes

  • N/A

Release notes snippet

  • Selection handlers receive the entity being edited, so a handler can leave the entity out of its own suggestions.
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

rwohleb created an issue. See original summary.

rwohleb’s picture

rwohleb’s picture

rwohleb’s picture

A slight refactor that passes through the entity to AutocompleteDeluxeElement via "#selection_settings" so that it's available to EntityAutocomplete::validateEntityAutocomplete().

rajab natshah’s picture

Issue summary: View changes
rajab natshah’s picture

Status: Active » Needs review
tivi22’s picture

Hi, is it possible to add a patch working with 2.0.3 version?

zarpele’s picture

Attaching patch against 2.0.3 version

zarpele’s picture

Attaching a patch against 2.1.2 version

rajab natshah’s picture

Version: 2.0.x-dev » 2.1.x-dev
Assigned: Unassigned » rajab natshah
Issue summary: View changes
StatusFileSize
new77.15 KB

Thank you, Robert for reporting and the first patches, and Guido for carrying them to 2.0.3 and 2.1.2.

Took the latest patch as the base and hardened the controller: the entity is only put into the selection settings when it loads and the user may view it, and an unknown entity type is caught, so a crafted request cannot break the route or hand a plugin an entity the user cannot see. The hashed settings and the key value store keep leaving the entity out, so one field keeps one key in the store.

Tested on a fresh Drupal 11 site built for this issue, with a small selection plugin that excludes the term named like the host entity: on the edit form of a node titled Alpha, typing Al offers Albion and Alps only, the add form offers all three, and requests with an unknown type, another entity or a missing id answer 200 and skip the entity.

The edit form of a node titled Alpha, with Alpha left out of the suggestions

To review, test, then merge.

  • rajab natshah committed 7e7c6f69 on 2.1.x
    feat: #3268207 Hand the entity being edited to the selection plugin
    
rajab natshah’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

rajab natshah’s picture

Assigned: rajab natshah » Unassigned

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.