summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorAlex Pott2019-01-07 09:28:56 (GMT)
committerAlex Pott2019-01-07 09:29:04 (GMT)
commit6cd36113bf64d76b3a126234cf3bb058103a5a4f (patch)
treed8c58af7c93ae549cab97dc93d7f13aeaa933696 /core
parent6b5cd5cd578e04592a76ca6e75c6cf040e004a42 (diff)
Issue #2693727 by mikelutz, sanduhrs, CalebD, ajlib, Lendude, tstoeckler, catch: Limiting options for exposed Language filters causes errors and doesn't work for special languages
(cherry picked from commit 0b6c398e7bf70ebac23881c24ee94bdaf6241dca)
Diffstat (limited to 'core')
-rw-r--r--core/modules/views/src/Plugin/views/filter/InOperator.php7
-rw-r--r--core/modules/views/tests/src/Kernel/Handler/FilterInOperatorTest.php35
2 files changed, 39 insertions, 3 deletions
diff --git a/core/modules/views/src/Plugin/views/filter/InOperator.php b/core/modules/views/src/Plugin/views/filter/InOperator.php
index e0add0f..8a88489 100644
--- a/core/modules/views/src/Plugin/views/filter/InOperator.php
+++ b/core/modules/views/src/Plugin/views/filter/InOperator.php
@@ -2,6 +2,7 @@
namespace Drupal\views\Plugin\views\filter;
+use Drupal\Component\Render\MarkupInterface;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
@@ -263,15 +264,15 @@ class InOperator extends FilterPluginBase {
}
// Because options may be an array of strings, or an array of mixed arrays
- // and strings (optgroups) or an array of objects, we have to
- // step through and handle each one individually.
+ // and strings (optgroups), or an array of objects, or a form of Markup, we
+ // have to step through and handle each one individually.
$options = [];
foreach ($input as $id => $option) {
if (is_array($option)) {
$options[$id] = $this->reduceValueOptions($option);
continue;
}
- elseif (is_object($option)) {
+ elseif (is_object($option) && !$option instanceof MarkupInterface) {
$keys = array_keys($option->option);
$key = array_shift($keys);
if (isset($this->options['value'][$key])) {
diff --git a/core/modules/views/tests/src/Kernel/Handler/FilterInOperatorTest.php b/core/modules/views/tests/src/Kernel/Handler/FilterInOperatorTest.php
index e02a843..b7b76ce 100644
--- a/core/modules/views/tests/src/Kernel/Handler/FilterInOperatorTest.php
+++ b/core/modules/views/tests/src/Kernel/Handler/FilterInOperatorTest.php
@@ -2,7 +2,11 @@
namespace Drupal\Tests\views\Kernel\Handler;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
+use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
+use Drupal\views\Plugin\views\display\DisplayPluginBase;
+use Drupal\views\ViewExecutable;
use Drupal\views\Views;
/**
@@ -11,6 +15,7 @@ use Drupal\views\Views;
* @group views
*/
class FilterInOperatorTest extends ViewsKernelTestBase {
+ use StringTranslationTrait;
public static $modules = ['system'];
@@ -195,4 +200,34 @@ class FilterInOperatorTest extends ViewsKernelTestBase {
return $filters;
}
+ /**
+ * Tests that the InOperator filter can handle TranslateableMarkup.
+ */
+ public function testFilterOptionAsMarkup() {
+ $view = $this->prophesize(ViewExecutable::class);
+ $display = $this->prophesize(DisplayPluginBase::class);
+ $display->getOption('relationships')->willReturn(FALSE);
+ $view->display_handler = $display->reveal();
+
+ /** @var \Drupal\views\Plugin\ViewsHandlerManager $manager */
+ $manager = $this->container->get('plugin.manager.views.filter');
+ /** @var \Drupal\views\Plugin\views\filter\InOperator $operator */
+ $operator = $manager->createInstance('in_operator');
+ $options = ['value' => ['foo' => [], 'baz' => []]];
+ $operator->init($view->reveal(), $display->reveal(), $options);
+
+ $input_options = [
+ 'foo' => 'bar',
+ 'baz' => $this->t('qux'),
+ 'quux' => (object) ['option' => ['quux' => 'corge']],
+ ];
+ $reduced_values = $operator->reduceValueOptions($input_options);
+
+ $this->assertSame(['foo', 'baz'], array_keys($reduced_values));
+ $this->assertInstanceOf(TranslatableMarkup::class, $reduced_values['baz']);
+ $this->assertSame('qux', (string) $reduced_values['baz']);
+ $this->assertSame('bar', $reduced_values['foo']);
+
+ }
+
}