Commit 0b6c398e authored by alexpott's avatar alexpott

Issue #2693727 by mikelutz, sanduhrs, CalebD, ajlib, Lendude, tstoeckler,...

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
parent 2278ec80
......@@ -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 @@ public function reduceValueOptions($input = NULL) {
}
// 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])) {
......
......@@ -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 @@
* @group views
*/
class FilterInOperatorTest extends ViewsKernelTestBase {
use StringTranslationTrait;
public static $modules = ['system'];
......@@ -195,4 +200,34 @@ protected function getGroupedExposedFilters() {
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']);
}
}
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