Commit 6e7dfbc0 authored by alexpott's avatar alexpott

Issue #2247211 by blueminds, amateescu, xjm: Fixed Autocomplete widget doesn't...

Issue #2247211 by blueminds, amateescu, xjm: Fixed Autocomplete widget doesn't work on entity labels without a " (entity_id)" suffix.
parent 1b495397
...@@ -24,8 +24,9 @@ interface SelectionInterface { ...@@ -24,8 +24,9 @@ interface SelectionInterface {
* Returns a list of referenceable entities. * Returns a list of referenceable entities.
* *
* @return array * @return array
* An array of referenceable entities. Keys are entity IDs and * A nested array of entities, the first level is keyed by the
* values are (safe HTML) labels to be displayed to the user. * entity bundle, which contains an array of entity labels (safe HTML),
* keyed by the entity ID.
*/ */
public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0); public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0);
......
...@@ -220,7 +220,11 @@ public function validateReferenceableEntities(array $ids) { ...@@ -220,7 +220,11 @@ public function validateReferenceableEntities(array $ids) {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function validateAutocompleteInput($input, &$element, &$form_state, $form, $strict = TRUE) { public function validateAutocompleteInput($input, &$element, &$form_state, $form, $strict = TRUE) {
$entities = $this->getReferenceableEntities($input, '=', 6); $bundled_entities = $this->getReferenceableEntities($input, '=', 6);
$entities = array();
foreach ($bundled_entities as $entities_list) {
$entities += $entities_list;
}
$params = array( $params = array(
'%value' => $input, '%value' => $input,
'@value' => $input, '@value' => $input,
......
...@@ -79,7 +79,8 @@ public function testSupportedEntityTypesAndWidgets() { ...@@ -79,7 +79,8 @@ public function testSupportedEntityTypesAndWidgets() {
'name' => $entity_name, 'name' => $entity_name,
'user_id' => mt_rand(0, 128), 'user_id' => mt_rand(0, 128),
$this->fieldName . '[0][target_id]' => $referenced_entities[0]->label() . ' (' . $referenced_entities[0]->id() . ')', $this->fieldName . '[0][target_id]' => $referenced_entities[0]->label() . ' (' . $referenced_entities[0]->id() . ')',
$this->fieldName . '[1][target_id]' => $referenced_entities[1]->label() . ' (' . $referenced_entities[1]->id() . ')', // Test an input of the entity label without a ' (entity_id)' suffix.
$this->fieldName . '[1][target_id]' => $referenced_entities[1]->label(),
); );
$this->drupalPostForm($this->entityType . '/add', $edit, t('Save')); $this->drupalPostForm($this->entityType . '/add', $edit, t('Save'));
$this->assertFieldValues($entity_name, $referenced_entities); $this->assertFieldValues($entity_name, $referenced_entities);
...@@ -97,7 +98,8 @@ public function testSupportedEntityTypesAndWidgets() { ...@@ -97,7 +98,8 @@ public function testSupportedEntityTypesAndWidgets() {
$entity_name = $this->randomName(); $entity_name = $this->randomName();
$target_id = $referenced_entities[0]->label() . ' (' . $referenced_entities[0]->id() . ')'; $target_id = $referenced_entities[0]->label() . ' (' . $referenced_entities[0]->id() . ')';
$target_id .= ', ' . $referenced_entities[1]->label() . ' (' . $referenced_entities[1]->id() . ')'; // Test an input of the entity label without a ' (entity_id)' suffix.
$target_id .= ', ' . $referenced_entities[1]->label();
$edit = array( $edit = array(
'name' => $entity_name, 'name' => $entity_name,
'user_id' => mt_rand(0, 128), 'user_id' => mt_rand(0, 128),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment