diff --git a/core/lib/Drupal/Core/Field/FieldFilteredString.php b/core/lib/Drupal/Core/Field/FieldFilteredString.php index d41c366..8035e1a 100644 --- a/core/lib/Drupal/Core/Field/FieldFilteredString.php +++ b/core/lib/Drupal/Core/Field/FieldFilteredString.php @@ -77,45 +77,4 @@ public static function displayAllowedTags() { return '<' . implode('> <', static::allowedTags()) . '>'; } - /** - * Transforms the string given an option. - * - * @param string $option - * One of the following: - * - upper: makes the string uppercase. - * - lower: makes the string lowercase. - * - ucfirst: makes the string's first character uppercase. - * - ucwords: uppercase the first character of each word in the string. - * - * @return static - * If the case transformation does not affect the string the same object is - * returned. If it does, then a new object is returned, preserving - * immutability. - */ - public function caseTransform($option) { - $new_string = $this->string; - switch ($option) { - case 'upper': - $new_string = Unicode::strtoupper($this->string); - break; - case 'lower': - $new_string = Unicode::strtolower($this->string); - break; - case 'ucfirst': - $new_string = Unicode::ucfirst($this->string); - break; - case 'ucwords': - $new_string = Unicode::ucwords($this->string); - break; - } - if ($new_string !== $this->string) { - // The string can be considered safe because it must have been filtered - // during construction. - $new_object = new static(); - $new_object->string = $new_string; - return $new_object; - } - return $this; - } - } diff --git a/core/modules/options/src/Plugin/views/argument/StringListField.php b/core/modules/options/src/Plugin/views/argument/StringListField.php index 7a39b35..ddf764a 100644 --- a/core/modules/options/src/Plugin/views/argument/StringListField.php +++ b/core/modules/options/src/Plugin/views/argument/StringListField.php @@ -81,14 +81,9 @@ public function summaryName($data) { $value = $data->{$this->name_alias}; // If the list element has a human readable name show it. if (isset($this->allowedValues[$value]) && !empty($this->options['summary']['human'])) { - $value = FieldFilteredString::create($this->allowedValues[$value]); + $value = $this->allowedValues[$value]; } - // Else, fallback to the key. - else { - // Filtering an escaped string will not change it. - $value = FieldFilteredString::create(SafeMarkup::checkPlain($value)); - } - return $value->caseTransform($this->options['case']); + return FieldFilteredString::create($this->caseTransform($value, $this->options['case'])); } } diff --git a/core/modules/views/src/Plugin/views/argument/ListString.php b/core/modules/views/src/Plugin/views/argument/ListString.php index 83419eb..5b10132 100644 --- a/core/modules/views/src/Plugin/views/argument/ListString.php +++ b/core/modules/views/src/Plugin/views/argument/ListString.php @@ -73,14 +73,9 @@ public function summaryName($data) { $value = $data->{$this->name_alias}; // If the list element has a human readable name show it, if (isset($this->allowed_values[$value]) && !empty($this->options['summary']['human'])) { - $value = FieldFilteredString::create($this->allowed_values[$value]); + $value = $this->allowed_values[$value]; } - // else fallback to the key. - else { - // Filtering an escaped string will not change it. - $value = FieldFilteredString::create(SafeMarkup::checkPlain($value)); - } - return $value->caseTransform($this->options['case']); + return FieldFilteredString::create($this->caseTransform($value, $this->options['case'])); } } diff --git a/core/tests/Drupal/Tests/Core/Field/FieldFilteredStringTest.php b/core/tests/Drupal/Tests/Core/Field/FieldFilteredStringTest.php index c595b75..0289bd7 100644 --- a/core/tests/Drupal/Tests/Core/Field/FieldFilteredStringTest.php +++ b/core/tests/Drupal/Tests/Core/Field/FieldFilteredStringTest.php @@ -63,33 +63,4 @@ public function testdisplayAllowedTags() { $this->assertSame($expected, FieldFilteredString::displayAllowedTags()); } - /** - * @covers ::caseTransform - * @dataProvider providertestCaseTransform - */ - public function testCaseTransform($option, $test_string, $expected) { - $filtered_string = FieldFilteredString::create($test_string); - $this->assertEquals($expected, $filtered_string->caseTransform($option)); - } - - /** - * Provides data for testCaseTransform(). - */ - public function providertestCaseTransform() { - $data = []; - $data[] = [ - 'upper', 'teststring', 'TESTSTRING' - ]; - $data[] = [ - 'lower', 'TESTSTRING', 'teststring' - ]; - $data[] = [ - 'ucfirst', 'teststring', 'Teststring' - ]; - $data[] = [ - 'ucwords', 'teststring and teststring', 'Teststring And Teststring' - ]; - return $data; - } - }