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 {
* Returns a list of referenceable entities.
*
* @return array
* An array of referenceable entities. Keys are entity IDs and
* values are (safe HTML) labels to be displayed to the user.
* A nested array of entities, the first level is keyed by the
* 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);
......
......@@ -220,7 +220,11 @@ public function validateReferenceableEntities(array $ids) {
* {@inheritdoc}
*/
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(
'%value' => $input,
'@value' => $input,
......
......@@ -79,7 +79,8 @@ public function testSupportedEntityTypesAndWidgets() {
'name' => $entity_name,
'user_id' => mt_rand(0, 128),
$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->assertFieldValues($entity_name, $referenced_entities);
......@@ -97,7 +98,8 @@ public function testSupportedEntityTypesAndWidgets() {
$entity_name = $this->randomName();
$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(
'name' => $entity_name,
'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