Verified Commit b78c8746 authored by Jess's avatar Jess
Browse files

Revert "Issue #3383131 by WalkingDexter, xjm, allisonherodevs, ashley_herodev,...

Revert "Issue #3383131 by WalkingDexter, xjm, allisonherodevs, ashley_herodev, pradhumanjain2311, smustgrave, marcoliver, lauriii: Entity autocomplete form element ignores entities with label "0""

This reverts commit 18732679.
parent 18732679
Loading
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -203,8 +203,7 @@ public static function processEntityAutocomplete(array &$element, FormStateInter
  public static function validateEntityAutocomplete(array &$element, FormStateInterface $form_state, array &$complete_form) {
    $value = NULL;

    // Check the value for emptiness, but allow the use of (string) "0".
    if ((!empty($element['#value']) || (is_string($element['#value']) && strlen($element['#value'])))) {
    if (!empty($element['#value'])) {
      $options = $element['#selection_settings'] + [
        'target_type' => $element['#target_type'],
        'handler' => $element['#selection_handler'],
+1 −5
Original line number Diff line number Diff line
@@ -77,12 +77,8 @@ public static function create(ContainerInterface $container) {
   */
  public function handleAutocomplete(Request $request, $target_type, $selection_handler, $selection_settings_key) {
    $matches = [];

    // Get the typed string from the URL, if it exists.
    $input = $request->query->get('q');

    // Check this string for emptiness, but allow any non-empty string.
    if (is_string($input) && strlen($input)) {
    if ($input = $request->query->get('q')) {
      $tag_list = Tags::explode($input);
      $typed_string = !empty($tag_list) ? mb_strtolower(array_pop($tag_list)) : '';

+0 −15
Original line number Diff line number Diff line
@@ -92,12 +92,6 @@ protected function setUp(): void {
      $entity->save();
      $this->referencedEntities[] = $entity;
    }

    $entity = EntityTest::create([
      'name' => '0',
    ]);
    $entity->save();
    $this->referencedEntities[] = $entity;
  }

  /**
@@ -190,11 +184,6 @@ public function buildForm(array $form, FormStateInterface $form_state) {
      '#tags' => TRUE,
    ];

    $form['single_name_0'] = [
      '#type' => 'entity_autocomplete',
      '#target_type' => 'entity_test',
    ];

    return $form;
  }

@@ -222,7 +211,6 @@ public function testValidEntityAutocompleteElement() {
        'tags_autocreate_specific_uid' => $this->getAutocompleteInput($this->referencedEntities[0]) . ', tags - autocreated entity label with specific uid, ' . $this->getAutocompleteInput($this->referencedEntities[1]),
        'single_string_id' => $this->getAutocompleteInput($this->referencedEntities[2]),
        'tags_string_id' => $this->getAutocompleteInput($this->referencedEntities[2]) . ', ' . $this->getAutocompleteInput($this->referencedEntities[3]),
        'single_name_0' => $this->referencedEntities[4]->label(),
      ]);
    $form_builder = $this->container->get('form_builder');
    $form_builder->submitForm($this, $form_state);
@@ -283,9 +271,6 @@ public function testValidEntityAutocompleteElement() {
      ['target_id' => $this->referencedEntities[3]->id()],
    ];
    $this->assertEquals($expected, $form_state->getValue('tags_string_id'));

    // Test the 'single_name_0' element.
    $this->assertEquals($this->referencedEntities[4]->id(), $form_state->getValue('single_name_0'));
  }

  /**
+3 −11
Original line number Diff line number Diff line
@@ -106,11 +106,9 @@ public function testEntityReferenceAutocompletion() {
    ];
    $this->assertSame($target, reset($data), 'Autocomplete returns an entity label containing a comma and a slash.');

    // Test empty input.
    foreach (['', NULL, FALSE, 0, 0.0] as $input) {
    $input = '';
    $data = $this->getAutocompleteResult($input);
      $this->assertSame([], $data, 'Autocomplete of empty input returns empty result');
    }
    $this->assertSame([], $data, 'Autocomplete of empty string returns empty result');

    $input = ',';
    $data = $this->getAutocompleteResult($input);
@@ -132,12 +130,6 @@ public function testEntityReferenceAutocompletion() {
    $this->assertSame(Html::escape($entity_1->name->value), $data[0]['label'], 'Autocomplete returned the first matching entity');
    $this->assertSame(Html::escape($entity_2->name->value), $data[1]['label'], 'Autocomplete returned the second matching entity');
    $this->assertSame(Html::escape($entity_3->name->value), $data[2]['label'], 'Autocomplete returned the third matching entity');

    // Try to autocomplete an entity label with the '0' character.
    $input = '0';
    $data = $this->getAutocompleteResult($input);
    $this->assertSame(Html::escape($entity_1->name->value), $data[0]['label'], 'Autocomplete returned the first matching entity');
    $this->assertSame(Html::escape($entity_2->name->value), $data[1]['label'], 'Autocomplete returned the second matching entity');
  }

  /**