Issue #2247211 by blueminds, amateescu, xjm: Fixed Autocomplete widget doesn't work on entity labels without a " (entity_id)" suffix.

8.0.x
Alex Pott 2014-06-03 00:31:57 -05:00
parent 1b49539704
commit 6e7dfbc0b7
3 changed files with 12 additions and 5 deletions

View File

@ -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);

View File

@ -220,7 +220,11 @@ class SelectionBase implements SelectionInterface {
* {@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,

View File

@ -79,7 +79,8 @@ class EntityReferenceIntegrationTest extends WebTestBase {
'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 @@ class EntityReferenceIntegrationTest extends WebTestBase {
$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),