Commit 0c4c1fd0 authored by Volodymyr Mostepaniuk's avatar Volodymyr Mostepaniuk
Browse files

Issue #3303413 by mostepaniukvm: Use dynamic entity id key.

parent a404fde2
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -2,7 +2,9 @@

namespace Drupal\autocomplete_id\Element;

use Drupal\Component\Utility\Tags;
use Drupal\Core\Entity\Element\EntityAutocomplete;
use Drupal\Core\Entity\EntityReferenceSelection\SelectionWithAutocreateInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface;

@@ -169,13 +171,15 @@ class EntityIdAutocomplete extends EntityAutocomplete {
   *   Value of a matching entity ID, or NULL if none.
   */
  protected static function matchEntityById(SelectionInterface $handler, $input, array &$element, FormStateInterface $form_state, $strict) {

    $entities = \Drupal::entityTypeManager()->getStorage($element['#target_type'])->loadByProperties(['id' => $input]);
    $entity_type_manager = \Drupal::entityTypeManager();
    $entity_type = $entity_type_manager->getDefinition($element['#target_type']);
    $entity_id_key = $entity_type->getKey('id');
    $entities = $entity_type_manager->getStorage($element['#target_type'])->loadByProperties([$entity_id_key => $input]);

    $params = [
      '%value' => $input,
      '@value' => $input,
      '@entity_type_plural' => \Drupal::entityTypeManager()->getDefinition($element['#target_type'])->getPluralLabel(),
      '@entity_type_plural' => $entity_type->getPluralLabel(),
    ];
    if (empty($entities)) {
      if ($strict) {