summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2016-11-03 12:01:07 (GMT)
committerNathaniel Catchpole2016-11-03 12:01:07 (GMT)
commitf6b3dd94810f62eb23034913ba624a072ef20b2d (patch)
tree73fa17cac60b76428169119664c9d31ced57a841
parent329c020e12afe0f54d2e12de3de114e47679c4bc (diff)
Issue #2809555 by jonathanjfshaw, alexpott, amateescu, Lendude, catch: ER views autocomplete fail to recognise exact matches typed in
-rw-r--r--core/modules/views/src/Plugin/views/display/EntityReference.php9
-rw-r--r--core/modules/views/src/Tests/Plugin/DisplayEntityReferenceTest.php57
2 files changed, 63 insertions, 3 deletions
diff --git a/core/modules/views/src/Plugin/views/display/EntityReference.php b/core/modules/views/src/Plugin/views/display/EntityReference.php
index 22c8c8c..bf2d460 100644
--- a/core/modules/views/src/Plugin/views/display/EntityReference.php
+++ b/core/modules/views/src/Plugin/views/display/EntityReference.php
@@ -122,9 +122,12 @@ class EntityReference extends DisplayPluginBase {
// Restrict the autocomplete options based on what's been typed already.
if (isset($options['match'])) {
$style_options = $this->getOption('style');
- $value = db_like($options['match']) . '%';
- if ($options['match_operator'] != 'STARTS_WITH') {
- $value = '%' . $value;
+ $value = db_like($options['match']);
+ if ($options['match_operator'] !== '=') {
+ $value = $value . '%';
+ if ($options['match_operator'] != 'STARTS_WITH') {
+ $value = '%' . $value;
+ }
}
// Multiple search fields are OR'd together.
diff --git a/core/modules/views/src/Tests/Plugin/DisplayEntityReferenceTest.php b/core/modules/views/src/Tests/Plugin/DisplayEntityReferenceTest.php
index 67d4d45..96d0369 100644
--- a/core/modules/views/src/Tests/Plugin/DisplayEntityReferenceTest.php
+++ b/core/modules/views/src/Tests/Plugin/DisplayEntityReferenceTest.php
@@ -103,6 +103,21 @@ class DisplayEntityReferenceTest extends PluginTestBase {
$this->fieldName => 'text' . $i,
])->save();
}
+ EntityTest::create([
+ 'bundle' => 'entity_test',
+ 'name' => 'name',
+ $this->fieldName => 'tex',
+ ])->save();
+ EntityTest::create([
+ 'bundle' => 'entity_test',
+ 'name' => 'name',
+ $this->fieldName => 'TEX',
+ ])->save();
+ EntityTest::create([
+ 'bundle' => 'entity_test',
+ 'name' => 'name',
+ $this->fieldName => 'sometext',
+ ])->save();
}
/**
@@ -140,6 +155,48 @@ class DisplayEntityReferenceTest extends PluginTestBase {
$this->assertEqual(count($view->result), 2, 'Search returned two rows');
$view->destroy();
+ // Test the 'CONTAINS' match_operator.
+ $view = Views::getView('test_display_entity_reference');
+ $view->setDisplay('entity_reference_1');
+ $options = [
+ 'match' => 'tex',
+ 'match_operator' => 'CONTAINS',
+ 'limit' => 0,
+ 'ids' => NULL,
+ ];
+ $view->display_handler->setOption('entity_reference_options', $options);
+ $this->executeView($view);
+ $this->assertEqual(count($view->result), 13, 'Search returned thirteen rows');
+ $view->destroy();
+
+ // Test the 'STARTS_WITH' match_operator.
+ $view = Views::getView('test_display_entity_reference');
+ $view->setDisplay('entity_reference_1');
+ $options = [
+ 'match' => 'tex',
+ 'match_operator' => 'STARTS_WITH',
+ 'limit' => 0,
+ 'ids' => NULL,
+ ];
+ $view->display_handler->setOption('entity_reference_options', $options);
+ $this->executeView($view);
+ $this->assertEqual(count($view->result), 12, 'Search returned twelve rows');
+ $view->destroy();
+
+ // Test the '=' match_operator.
+ $view = Views::getView('test_display_entity_reference');
+ $view->setDisplay('entity_reference_1');
+ $options = [
+ 'match' => 'tex',
+ 'match_operator' => '=',
+ 'limit' => 0,
+ 'ids' => NULL,
+ ];
+ $view->display_handler->setOption('entity_reference_options', $options);
+ $this->executeView($view);
+ $this->assertEqual(count($view->result), 2, 'Search returned two rows');
+ $view->destroy();
+
// Add a relationship and a field using that relationship.
$this->drupalPostForm('admin/structure/views/nojs/add-handler/test_display_entity_reference/default/relationship', ['name[entity_test.user_id]' => TRUE], t('Add and configure relationships'));
$this->drupalPostForm(NULL, [], t('Apply'));