Problem/Motivation

The default element_validate, validateEntityAutocomplete attempts to matchEntityByTitle if it does not find entity id in the expected format 'Title (id)'.

Steps to reproduce

Enter an entity id and submit the form before the autocomplete finishes.

Proposed resolution

Add a method to EntityIdAutocomplete to validate the element. Set the element validation in getInfo.

Remaining tasks

  1. create EntityIdAutocomplete ::validateEntityIdAutocomplete method
  2. Add EntityIdAutocomplete ::getInfo
CommentFileSizeAuthor
#2 3303413-element-validate-2.patch7.71 KBbluegeek9
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

bluegeek9 created an issue. See original summary.

bluegeek9’s picture

Status: Active » Needs review
StatusFileSize
new7.71 KB

bluegeek9’s picture

Status: Needs review » Fixed

  • bluegeek9 committed ec575eb on 8.x-1.x
    Issue #3303413 by bluegeek9: custom #element_validate
    
bluegeek9’s picture

Status: Fixed » Active

Line 173 of src/Element/EntityIdAutocomplete.php needs to be changed. Not all entities use id as an id. Nodes use nid.

    $entities = \Drupal::entityTypeManager()->getStorage($element['#target_type'])->loadByProperties(['id' => $input]);
    $entities = \Drupal::entityTypeManager()->getStorage($element['#target_type'])->load($input);

mostepaniukvm made their first commit to this issue’s fork.

mostepaniukvm’s picture

Status: Active » Needs review

  • 0c4c1fd committed on 8.x-1.x
    Issue #3303413 by mostepaniukvm: Use dynamic entity id key.
    
mostepaniukvm’s picture

Status: Needs review » Fixed

Merged PR to fix bugs in dev version. Tagged new d10 compatible release. Feel free to review changes and reopen afterward if needed.
Set issue to fixed

Status: Fixed » Closed (fixed)

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