diff --git a/core/lib/Drupal/Core/Template/TwigExtension.php b/core/lib/Drupal/Core/Template/TwigExtension.php index 9cd17b0..0631a28 100644 --- a/core/lib/Drupal/Core/Template/TwigExtension.php +++ b/core/lib/Drupal/Core/Template/TwigExtension.php @@ -23,9 +23,7 @@ public function getFunctions() { // @todo Remove URL function once http://drupal.org/node/1778610 is resolved. 'url' => new \Twig_Function_Function('url'), // These functions will receive a TwigReference object, if a render array is detected - 'hide' => new TwigReferenceFunction('twig_hide'), 'render_var' => new TwigReferenceFunction('twig_render_var'), - 'show' => new TwigReferenceFunction('twig_show'), ); } @@ -40,6 +38,7 @@ public function getFilters() { // @see TwigNodeTrans::compileString() 'passthrough' => new \Twig_Filter_Function('twig_raw_filter'), 'placeholder' => new \Twig_Filter_Function('twig_raw_filter'), + 'without' => new \Twig_Filter_Function('twig_without'), ); } @@ -53,8 +52,6 @@ public function getNodeVisitors() { public function getTokenParsers() { return array( - new TwigFunctionTokenParser('hide'), - new TwigFunctionTokenParser('show'), new TwigTransTokenParser(), ); } diff --git a/core/modules/block/templates/block-list.html.twig b/core/modules/block/templates/block-list.html.twig index 873d192..474c654 100644 --- a/core/modules/block/templates/block-list.html.twig +++ b/core/modules/block/templates/block-list.html.twig @@ -13,10 +13,9 @@ * @ingroup themeable */ #} -{% hide(form.place_blocks) %}
- {{ form }} + {{ form|without('place_blocks') }}
{{ form.place_blocks }} diff --git a/core/modules/comment/templates/comment.html.twig b/core/modules/comment/templates/comment.html.twig index 570448f..c26b4b6 100644 --- a/core/modules/comment/templates/comment.html.twig +++ b/core/modules/comment/templates/comment.html.twig @@ -7,8 +7,11 @@ * - author: Comment author. Can be a link or plain text. * - content: The content-related items for the comment display. Use * {{ content }} to print them all, or print a subset such as - * {{ content.field_example }}. Use hide(content.field_example) to temporarily - * suppress the printing of a given element. + * {{ content.field_example }}. Use following code to temporarily suppress the + * printing of a given child element: + * @code + * {{ content|without('field_example') }} + * @endcode * - created: Formatted date and time for when the comment was created. * Preprocess functions can reformat it by calling format_date() with the * desired parameters on the 'comment.created' variable. @@ -93,8 +96,7 @@ {# We hide the links now so that we can render them later. #} - {% hide(content.links) %} - {{ content }} + {{ content|without('links') }} {% if signature %}
diff --git a/core/modules/node/templates/node-edit-form.html.twig b/core/modules/node/templates/node-edit-form.html.twig index eee9ecc..c208cf5 100644 --- a/core/modules/node/templates/node-edit-form.html.twig +++ b/core/modules/node/templates/node-edit-form.html.twig @@ -15,11 +15,9 @@ * @ingroup themeable */ #} -{% hide(form.advanced) %} -{% hide(form.actions) %}
- {{ form }} + {{ form|without('advanced', 'actions') }}
{{ form.advanced }} diff --git a/core/modules/node/templates/node.html.twig b/core/modules/node/templates/node.html.twig index 1f8c823..55d5589 100644 --- a/core/modules/node/templates/node.html.twig +++ b/core/modules/node/templates/node.html.twig @@ -18,8 +18,8 @@ * - label: The title of the node. * - content: All node items. Use {{ content }} to print them all, * or print a subset such as {{ content.field_example }}. Use - * {% hide(content.field_example) %} to temporarily suppress the printing - * of a given element. + * {{ content|without('field_example') %} to temporarily suppress the printing + * of a given child element. * - user_picture: The node author's picture from user-picture.html.twig. * - date: Formatted creation date. Preprocess functions can reformat it by * calling format_date() with the desired parameters on @@ -94,8 +94,7 @@ {# We hide links now so that we can render them later. #} - {% hide(content.links) %} - {{ content }} + {{ content|without('links') }}
{{ content.links }} diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/TwigFilterTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/TwigFilterTest.php new file mode 100644 index 0000000..4f58b4d --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/TwigFilterTest.php @@ -0,0 +1,85 @@ + 'Twig Filters', + 'description' => 'Test Drupal\'s Twig filters.', + 'group' => 'Theme', + ); + } + + /** + * Test Twig "trans" tags. + */ + public function testTwigTransTags() { + $this->drupalGet('/twig-theme-test/filter'); + + $elements = array( + array( + 'expected' => '
No author: You can only find truth with logic if you have already found truth without it.1874-1936.
', + 'message' => '"No author" was successfully rendered.', + ), + array( + 'expected' => '
Complete quote after without: You can only find truth with logic if you have already found truth without it.Gilbert Keith Chesterton1874-1936.
', + 'message' => '"Complete quote after without" was successfully rendered.', + ), + array( + 'expected' => '
Only author: Gilbert Keith Chesterton.
', + 'message' => '"Only author:" was successfully rendered.', + ), + array( + 'expected' => '
No author or date: You can only find truth with logic if you have already found truth without it..
', + 'message' => '"No author or date" was successfully rendered.', + ), + array( + 'expected' => '
Only date: 1874-1936.
', + 'message' => '"Only date" was successfully rendered.', + ), + array( + 'expected' => '
Complete quote again for good measure: You can only find truth with logic if you have already found truth without it.Gilbert Keith Chesterton1874-1936.
', + 'message' => '"Complete quote again for good measure" was successfully rendered.', + ), + array( + 'expected' => '
Marked-up: +
+

You can only find truth with logic if you have already found truth without it.

+ +
', + 'message' => '"Marked-up quote" was successfully rendered.', + ), + ); + + foreach ($elements as $element) { + $this->assertRaw($element['expected'], $element['message']); + } + } + +} diff --git a/core/modules/system/tests/modules/twig_extension_test/lib/Drupal/twig_extension_test/TwigExtension/TestExtension.php b/core/modules/system/tests/modules/twig_extension_test/lib/Drupal/twig_extension_test/TwigExtension/TestExtension.php index 93da633..3c2b851 100644 --- a/core/modules/system/tests/modules/twig_extension_test/lib/Drupal/twig_extension_test/TwigExtension/TestExtension.php +++ b/core/modules/system/tests/modules/twig_extension_test/lib/Drupal/twig_extension_test/TwigExtension/TestExtension.php @@ -8,7 +8,6 @@ namespace Drupal\twig_extension_test\TwigExtension; use Drupal\Core\Template\TwigExtension; -use Drupal\Core\Template\TwigReferenceFunction; /** * A test Twig extension that adds a custom function and a custom filter. 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 45654ea..ba2a718 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,4 +28,19 @@ 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 new file mode 100644 index 0000000..ce4c405 --- /dev/null +++ b/core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.filter.html.twig @@ -0,0 +1,14 @@ +
No author: {{ quote|without('author') }}.
+
Complete quote after without: {{ quote }}.
+
Only author: {{ quote.author }}.
+
No author or date: {{ quote|without('date', 'author') }}.
+
Only date: {{ quote.date }}.
+
Complete quote again for good measure: {{ quote }}.
+
Marked-up: +
+

{{ quote.content }}

+ +
+
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 6edb6f6..e47b30c 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 @@ -4,6 +4,10 @@ * Implements hook_theme(). */ function twig_theme_test_theme($existing, $type, $theme, $path) { + $items['twig_theme_test_filter'] = array( + 'variables' => array('quote' => array()), + 'template' => 'twig_theme_test.filter', + ); $items['twig_theme_test_php_variables'] = array( 'template' => 'twig_theme_test.php_variables', ); 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 96befd4..c187bc2 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,3 +11,10 @@ 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/modules/taxonomy/templates/taxonomy-term.html.twig b/core/modules/taxonomy/templates/taxonomy-term.html.twig index a3986fa..2ecc713 100644 --- a/core/modules/taxonomy/templates/taxonomy-term.html.twig +++ b/core/modules/taxonomy/templates/taxonomy-term.html.twig @@ -8,10 +8,10 @@ * - name: Name of the current term. * - content: Items for the content of the term (fields and description). * Use 'content' to print them all, or print a subset such as - * 'content.description'. Use the following code to temporarily suppress the - * printing of a given element: + * 'content.description'. Use the following code to exclude the + * printing of a given child element: * @code - * {% hide(content.description) %} + * {{ content|without('description') }} * @endcode * - attributes: HTML attributes for the wrapper. The 'class' attribute * contains the following classes by default: diff --git a/core/themes/bartik/templates/comment.html.twig b/core/themes/bartik/templates/comment.html.twig index ad03eb6..cfc56f6 100644 --- a/core/themes/bartik/templates/comment.html.twig +++ b/core/themes/bartik/templates/comment.html.twig @@ -7,8 +7,11 @@ * - author: Comment author. Can be a link or plain text. * - content: The content-related items for the comment display. Use * {{ content }} to print them all, or print a subset such as - * {{ content.field_example }}. Use hide(content.field_example) to temporarily - * suppress the printing of a given element. + * {{ content.field_example }}. Use following code to temporarily suppress the + * printing of a given child element: + * @code + * {{ content|without('field_example') }} + * @endcode * - created: Formatted date and time for when the comment was created. * Preprocess functions can reformat it by calling format_date() with the * desired parameters on the 'comment.created' variable. @@ -107,8 +110,7 @@ {# We hide the links now so that we can render them later. #} - {% hide(content.links) %} - {{ content }} + {{ content|without('links') }}