Commit ffc1f757 authored by catch's avatar catch

Issue #2543796 by mikeker, therealssj, mariagwyn: Using token views to rewrite...

Issue #2543796 by mikeker, therealssj, mariagwyn: Using token views to rewrite css output causes Twig_Error_Syntax, "Unexpected token "end of template" of value " in Twig/ExpressionParser.php line 190
parent d8693fe8
......@@ -321,9 +321,9 @@ public function getElements() {
* {@inheritdoc}
*/
public function elementClasses($row_index = NULL) {
$classes = explode(' ', $this->options['element_class']);
$classes = $this->tokenizeValue($this->options['element_class'], $row_index);
$classes = explode(' ', $classes);
foreach ($classes as &$class) {
$class = $this->tokenizeValue($class, $row_index);
$class = Html::cleanCssIdentifier($class);
}
return implode(' ', $classes);
......@@ -368,9 +368,9 @@ public function tokenizeValue($value, $row_index = NULL) {
* {@inheritdoc}
*/
public function elementLabelClasses($row_index = NULL) {
$classes = explode(' ', $this->options['element_label_class']);
$classes = $this->tokenizeValue($this->options['element_label_class'], $row_index);
$classes = explode(' ', $classes);
foreach ($classes as &$class) {
$class = $this->tokenizeValue($class, $row_index);
$class = Html::cleanCssIdentifier($class);
}
return implode(' ', $classes);
......@@ -380,9 +380,9 @@ public function elementLabelClasses($row_index = NULL) {
* {@inheritdoc}
*/
public function elementWrapperClasses($row_index = NULL) {
$classes = explode(' ', $this->options['element_wrapper_class']);
$classes = $this->tokenizeValue($this->options['element_wrapper_class'], $row_index);
$classes = explode(' ', $classes);
foreach ($classes as &$class) {
$class = $this->tokenizeValue($class, $row_index);
$class = Html::cleanCssIdentifier($class);
}
return implode(' ', $classes);
......
......@@ -717,6 +717,50 @@ public function testGetRenderTokensWithArguments() {
$this->assertEquals($expected, $field->getRenderTokens([]));
}
/**
* Ensures proper token replacement when generating CSS classes.
*
* @covers ::elementClasses
* @covers ::elementLabelClasses
* @covers ::elementWrapperClasses
*/
public function testElementClassesWithTokens() {
$functions = [
'elementClasses' => 'element_class',
'elementLabelClasses' => 'element_label_class',
'elementWrapperClasses' => 'element_wrapper_class',
];
$tokens = ['test_token' => 'foo'];
$test_class = 'test-class-without-token test-class-with-{{ test_token }}-token';
$expected_result = 'test-class-without-token test-class-with-foo-token';
// Inline template to render the tokens.
$build = [
'#type' => 'inline_template',
'#template' => $test_class,
'#context' => $tokens,
'#post_render' => [function() {}],
];
// We're not testing the token rendering itself, just that the function
// being tested correctly handles tokens when generating the element's class
// attribute.
$this->renderer->expects($this->any())
->method('renderPlain')
->with($build)
->willReturn($expected_result);
foreach ($functions as $callable => $option_name) {
$field = $this->setupTestField([$option_name => $test_class]);
$field->view->style_plugin = new \stdClass();
$field->view->style_plugin->render_tokens[] = $tokens;
$result = $field->{$callable}(0);
$this->assertEquals($expected_result, $result);
}
}
}
class FieldPluginBaseTestField extends FieldPluginBase {
......
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