Skip to content
Snippets Groups Projects
Verified Commit d7537753 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

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

Issue #3383131 by WalkingDexter, xjm, allisonherodevs, ashley_herodev, pradhumanjain2311, smustgrave, marcoliver, lauriii: Entity autocomplete form element ignores entities with label "0"
parent 8c89656b
No related branches found
No related tags found
26 merge requests!8528Issue #3456871 by Tim Bozeman: Support NULL services,!3878Removed unused condition head title for views,!38582585169-10.1.x,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3668Resolve #3347842 "Deprecate the trusted",!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493
Pipeline #85230 passed
Pipeline: drupal

#85232

    ...@@ -203,7 +203,8 @@ public static function processEntityAutocomplete(array &$element, FormStateInter ...@@ -203,7 +203,8 @@ public static function processEntityAutocomplete(array &$element, FormStateInter
    public static function validateEntityAutocomplete(array &$element, FormStateInterface $form_state, array &$complete_form) { public static function validateEntityAutocomplete(array &$element, FormStateInterface $form_state, array &$complete_form) {
    $value = NULL; $value = NULL;
    if (!empty($element['#value'])) { // Check the value for emptiness, but allow the use of (string) "0".
    if (!empty($element['#value']) || (is_string($element['#value']) && strlen($element['#value']))) {
    $options = $element['#selection_settings'] + [ $options = $element['#selection_settings'] + [
    'target_type' => $element['#target_type'], 'target_type' => $element['#target_type'],
    'handler' => $element['#selection_handler'], 'handler' => $element['#selection_handler'],
    ......
    ...@@ -77,8 +77,12 @@ public static function create(ContainerInterface $container) { ...@@ -77,8 +77,12 @@ public static function create(ContainerInterface $container) {
    */ */
    public function handleAutocomplete(Request $request, $target_type, $selection_handler, $selection_settings_key) { public function handleAutocomplete(Request $request, $target_type, $selection_handler, $selection_settings_key) {
    $matches = []; $matches = [];
    // Get the typed string from the URL, if it exists. // Get the typed string from the URL, if it exists.
    if ($input = $request->query->get('q')) { $input = $request->query->get('q');
    // Check this string for emptiness, but allow any non-empty string.
    if (is_string($input) && strlen($input)) {
    $tag_list = Tags::explode($input); $tag_list = Tags::explode($input);
    $typed_string = !empty($tag_list) ? mb_strtolower(array_pop($tag_list)) : ''; $typed_string = !empty($tag_list) ? mb_strtolower(array_pop($tag_list)) : '';
    ......
    ...@@ -92,6 +92,12 @@ protected function setUp(): void { ...@@ -92,6 +92,12 @@ protected function setUp(): void {
    $entity->save(); $entity->save();
    $this->referencedEntities[] = $entity; $this->referencedEntities[] = $entity;
    } }
    $entity = EntityTest::create([
    'name' => '0',
    ]);
    $entity->save();
    $this->referencedEntities[] = $entity;
    } }
    /** /**
    ...@@ -184,6 +190,11 @@ public function buildForm(array $form, FormStateInterface $form_state) { ...@@ -184,6 +190,11 @@ public function buildForm(array $form, FormStateInterface $form_state) {
    '#tags' => TRUE, '#tags' => TRUE,
    ]; ];
    $form['single_name_0'] = [
    '#type' => 'entity_autocomplete',
    '#target_type' => 'entity_test',
    ];
    return $form; return $form;
    } }
    ...@@ -211,6 +222,7 @@ public function testValidEntityAutocompleteElement() { ...@@ -211,6 +222,7 @@ public function testValidEntityAutocompleteElement() {
    'tags_autocreate_specific_uid' => $this->getAutocompleteInput($this->referencedEntities[0]) . ', tags - autocreated entity label with specific uid, ' . $this->getAutocompleteInput($this->referencedEntities[1]), '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]), 'single_string_id' => $this->getAutocompleteInput($this->referencedEntities[2]),
    'tags_string_id' => $this->getAutocompleteInput($this->referencedEntities[2]) . ', ' . $this->getAutocompleteInput($this->referencedEntities[3]), '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 = $this->container->get('form_builder');
    $form_builder->submitForm($this, $form_state); $form_builder->submitForm($this, $form_state);
    ...@@ -271,6 +283,9 @@ public function testValidEntityAutocompleteElement() { ...@@ -271,6 +283,9 @@ public function testValidEntityAutocompleteElement() {
    ['target_id' => $this->referencedEntities[3]->id()], ['target_id' => $this->referencedEntities[3]->id()],
    ]; ];
    $this->assertEquals($expected, $form_state->getValue('tags_string_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'));
    } }
    /** /**
    ......
    ...@@ -106,9 +106,11 @@ public function testEntityReferenceAutocompletion() { ...@@ -106,9 +106,11 @@ public function testEntityReferenceAutocompletion() {
    ]; ];
    $this->assertSame($target, reset($data), 'Autocomplete returns an entity label containing a comma and a slash.'); $this->assertSame($target, reset($data), 'Autocomplete returns an entity label containing a comma and a slash.');
    $input = ''; // Test empty input.
    $data = $this->getAutocompleteResult($input); foreach (['', NULL, FALSE, 0, 0.0] as $input) {
    $this->assertSame([], $data, 'Autocomplete of empty string returns empty result'); $data = $this->getAutocompleteResult($input);
    $this->assertSame([], $data, 'Autocomplete of empty input returns empty result');
    }
    $input = ','; $input = ',';
    $data = $this->getAutocompleteResult($input); $data = $this->getAutocompleteResult($input);
    ...@@ -130,6 +132,12 @@ public function testEntityReferenceAutocompletion() { ...@@ -130,6 +132,12 @@ 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_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_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'); $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');
    } }
    /** /**
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment