diff --git a/core/lib/Drupal/Core/Template/Attribute.php b/core/lib/Drupal/Core/Template/Attribute.php index 7833acc..ead5d05 100644 --- a/core/lib/Drupal/Core/Template/Attribute.php +++ b/core/lib/Drupal/Core/Template/Attribute.php @@ -112,11 +112,9 @@ public function offsetExists($name) { public function __toString() { $return = ''; foreach ($this->storage as $name => $value) { - if (!$value->printed()) { - $rendered = $value->render(); - if ($rendered) { - $return .= ' ' . $rendered; - } + $rendered = $value->render(); + if ($rendered) { + $return .= ' ' . $rendered; } } return $return; diff --git a/core/lib/Drupal/Core/Template/AttributeArray.php b/core/lib/Drupal/Core/Template/AttributeArray.php index 38f216f..95e0ef3 100644 --- a/core/lib/Drupal/Core/Template/AttributeArray.php +++ b/core/lib/Drupal/Core/Template/AttributeArray.php @@ -66,7 +66,6 @@ public function offsetExists($offset) { * Implements the magic __toString() method. */ public function __toString() { - $this->printed = TRUE; return String::checkPlain(implode(' ', $this->value)); } diff --git a/core/lib/Drupal/Core/Template/AttributeBoolean.php b/core/lib/Drupal/Core/Template/AttributeBoolean.php index db444fd..4e9ea67 100644 --- a/core/lib/Drupal/Core/Template/AttributeBoolean.php +++ b/core/lib/Drupal/Core/Template/AttributeBoolean.php @@ -42,7 +42,6 @@ public function render() { * Implements the magic __toString() method. */ public function __toString() { - $this->printed = TRUE; return $this->value === FALSE ? '' : String::checkPlain($this->name); } diff --git a/core/lib/Drupal/Core/Template/AttributeString.php b/core/lib/Drupal/Core/Template/AttributeString.php index a2a5514..07211be 100644 --- a/core/lib/Drupal/Core/Template/AttributeString.php +++ b/core/lib/Drupal/Core/Template/AttributeString.php @@ -30,7 +30,6 @@ class AttributeString extends AttributeValueBase { * Implements the magic __toString() method. */ public function __toString() { - $this->printed = TRUE; return String::checkPlain($this->value); } diff --git a/core/lib/Drupal/Core/Template/AttributeValueBase.php b/core/lib/Drupal/Core/Template/AttributeValueBase.php index 6ccd339..73e6bee 100644 --- a/core/lib/Drupal/Core/Template/AttributeValueBase.php +++ b/core/lib/Drupal/Core/Template/AttributeValueBase.php @@ -17,13 +17,6 @@ abstract class AttributeValueBase { /** - * Whether this attribute hsa been printed already. - * - * @var bool - */ - protected $printed = FALSE; - - /** * The value itself. * * @var mixed @@ -61,16 +54,6 @@ public function render() { } /** - * Whether this attribute hsa been printed already. - * - * @return bool - * TRUE if this attribute has been printed, FALSE otherwise. - */ - public function printed() { - return $this->printed; - } - - /** * Implements the magic __toString() method. */ abstract function __toString(); diff --git a/core/modules/node/templates/node.html.twig b/core/modules/node/templates/node.html.twig index 5bf5ad9..ae1162e 100644 --- a/core/modules/node/templates/node.html.twig +++ b/core/modules/node/templates/node.html.twig @@ -75,7 +75,7 @@ * @ingroup themeable */ #} -
+
{{ title_prefix }} {% if not page %} diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/TwigFilterTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/TwigFilterTest.php index a80598c..9b514d7 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Theme/TwigFilterTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/TwigFilterTest.php @@ -8,6 +8,7 @@ namespace Drupal\system\Tests\Theme; use Drupal\simpletest\WebTestBase; +use Drupal\Core\Template\Attribute; /** * Tests Drupal's Twig filters. @@ -19,9 +20,7 @@ class TwigFilterTest extends WebTestBase { * * @var array */ - public static $modules = array( - 'twig_theme_test', - ); + public static $modules = array('twig_theme_test'); /** * {@inheritdoc} @@ -38,7 +37,21 @@ public static function getInfo() { * Test Twig "without" filter. */ public function testTwigWithoutFilter() { - $this->drupalGet('/twig-theme-test/filter'); + $filter_test = array( + '#theme' => 'twig_theme_test_filter', + '#quote' => array( + 'content' => array('#markup' => 'You can only find truth with logic if you have already found truth without it.'), + 'author' => array('#markup' => 'Gilbert Keith Chesterton'), + 'date' => array('#markup' => '1874-1936'), + ), + '#attributes' => array( + 'id' => 'quotes', + 'checked' => TRUE, + 'class' => array('red', 'green', 'blue'), + ), + ); + $rendered = drupal_render($filter_test); + $this->drupalSetContent($rendered); $elements = array( array( @@ -75,6 +88,38 @@ public function testTwigWithoutFilter() { ', 'message' => '"Marked-up quote" was successfully rendered.', ), + array( + 'expected' => '
All attributes:
', + 'message' => 'All attributes printed.', + ), + array( + 'expected' => '
Class attributes in front, remainder at the back:
', + 'message' => 'Class attributes printed in the front, the rest in the back.', + ), + array( + 'expected' => '
Class attributes in back, remainder at the front:
', + 'message' => 'Class attributes printed in the back, the rest in the front.', + ), + array( + 'expected' => '
Class attributes only:
', + 'message' => 'Class attributes only printed.', + ), + array( + 'expected' => '
Without boolean attribute.
', + 'message' => 'Boolean attribute printed in the front.', + ), + array( + 'expected' => '
Without string attribute.
', + 'message' => 'Without string attribute in the front.', + ), + array( + 'expected' => '
Without either nor class attributes.
', + 'message' => 'Attributes printed without id nor class attributes.', + ), + array( + 'expected' => '
All attributes again.
', + 'message' => 'All attributes printed again.', + ), ); foreach ($elements as $element) { diff --git a/core/modules/system/tests/modules/twig_theme_test/lib/Drupal/twig_theme_test/TwigThemeTestController.php b/core/modules/system/tests/modules/twig_theme_test/lib/Drupal/twig_theme_test/TwigThemeTestController.php index ba2a718..45654ea 100644 --- a/core/modules/system/tests/modules/twig_theme_test/lib/Drupal/twig_theme_test/TwigThemeTestController.php +++ b/core/modules/system/tests/modules/twig_theme_test/lib/Drupal/twig_theme_test/TwigThemeTestController.php @@ -28,19 +28,4 @@ public function transBlockRender() { ); } - /** - * Menu callback for filters in a Twig template. - */ - public function testFilterRender() { - return array( - '#theme' => 'twig_theme_test_filter', - '#quote' => array( - 'content' => array('#markup' => 'You can only find truth with logic if you have already found truth without it.'), - 'author' => array('#markup' => 'Gilbert Keith Chesterton'), - 'date' => array('#markup' => '1874-1936'), - ), - ); - } - } - diff --git a/core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.filter.html.twig b/core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.filter.html.twig index ce4c405..28e5c15 100644 --- a/core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.filter.html.twig +++ b/core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.filter.html.twig @@ -12,3 +12,11 @@ +
All attributes:
+
Class attributes in front, remainder at the back:
+
Class attributes in back, remainder at the front:
+
Class attributes only:
+
Without boolean attribute.
+
Without string attribute.
+
Without either nor class attributes.
+
All attributes again.
diff --git a/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module b/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module index 5a9f095..5874cca 100644 --- a/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module +++ b/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module @@ -5,7 +5,7 @@ */ function twig_theme_test_theme($existing, $type, $theme, $path) { $items['twig_theme_test_filter'] = array( - 'variables' => array('quote' => array()), + 'variables' => array('quote' => array(), 'attributes' => array()), 'template' => 'twig_theme_test.filter', ); $items['twig_theme_test_php_variables'] = array( diff --git a/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.routing.yml b/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.routing.yml index c187bc2..96befd4 100644 --- a/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.routing.yml +++ b/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.routing.yml @@ -11,10 +11,3 @@ twig_theme_test.trans: _content: '\Drupal\twig_theme_test\TwigThemeTestController::transBlockRender' requirements: _access: 'TRUE' - -twig_theme_test.filter: - path: '/twig-theme-test/filter' - defaults: - _content: '\Drupal\twig_theme_test\TwigThemeTestController::testFilterRender' - requirements: - _access: 'TRUE' diff --git a/core/themes/bartik/templates/comment.html.twig b/core/themes/bartik/templates/comment.html.twig index ea320b9..bbb7c5b 100644 --- a/core/themes/bartik/templates/comment.html.twig +++ b/core/themes/bartik/templates/comment.html.twig @@ -62,7 +62,7 @@ * @see template_preprocess_comment() */ #} -
+
diff --git a/core/themes/bartik/templates/field--taxonomy-term-reference.html.twig b/core/themes/bartik/templates/field--taxonomy-term-reference.html.twig index 59cd35e..fad1ed7 100644 --- a/core/themes/bartik/templates/field--taxonomy-term-reference.html.twig +++ b/core/themes/bartik/templates/field--taxonomy-term-reference.html.twig @@ -16,7 +16,7 @@ * @see bartik_preprocess_field() */ #} -
+
{{ label }}: