commit b4289fba8926240b2d1096b2b077cfc0876d91ed Author: Joel Pittet Date: Thu Mar 6 10:27:25 2014 -0800 doc cleanup diff --git a/core/lib/Drupal/Core/Template/TwigExtension.php b/core/lib/Drupal/Core/Template/TwigExtension.php index c172e12..7f39f26 100644 --- a/core/lib/Drupal/Core/Template/TwigExtension.php +++ b/core/lib/Drupal/Core/Template/TwigExtension.php @@ -21,24 +21,24 @@ public function getFunctions() { // @todo re-add unset => twig_unset if this is really needed return array( // @todo Remove URL function once http://drupal.org/node/1778610 is resolved. - 'url' => new \Twig_Function_Function('url'), + 'url' => new \Twig_SimpleFunction('url', 'url'), // This function will receive a renderable array, if an array is detected. - 'render_var' => new \Twig_Function_Function('twig_render_var'), + 'render_var' => new \Twig_SimpleFunction('render_var', 'twig_render_var'), ); } public function getFilters() { return array( - 't' => new \Twig_Filter_Function('t'), - 'trans' => new \Twig_Filter_Function('t'), + new \Twig_SimpleFilter('t', 't'), + new \Twig_SimpleFilter('trans', 't'), // The "raw" filter is not detectable when parsing "trans" tags. To detect // which prefix must be used for translation (@, !, %), we must clone the // "raw" filter and give it identifiable names. These filters should only // be used in "trans" tags. // @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'), + new \Twig_SimpleFilter('passthrough', 'twig_raw_filter'), + new \Twig_SimpleFilter('placeholder', 'twig_raw_filter'), + new \Twig_SimpleFilter('without', 'twig_without'), ); } diff --git a/core/lib/Drupal/Core/Template/TwigNodeVisitor.php b/core/lib/Drupal/Core/Template/TwigNodeVisitor.php index 75f1dce..a2cae19 100644 --- a/core/lib/Drupal/Core/Template/TwigNodeVisitor.php +++ b/core/lib/Drupal/Core/Template/TwigNodeVisitor.php @@ -10,8 +10,8 @@ /** * Provides a Twig_NodeVisitor to change the generated parse-tree. * - * This is used to ensure that everything printed is wrapped via the - * twig_render_var() function in order to just write {{ content }} + * This is used to ensure that everything that is printed is wrapped via + * twig_render_var() function so that we can write for example just {{ content }} * in templates instead of having to write {{ render_var(content) }}. * * @see twig_render @@ -26,7 +26,12 @@ function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env) { } /** - * {@inheritdoc} + * Implements Twig_NodeVisitorInterface::leaveNode(). + * + * We use this to inject a call to render_var -> twig_render_var() + * before anything is printed. + * + * @see twig_render */ function leaveNode(\Twig_NodeInterface $node, \Twig_Environment $env) { // We use this to inject a call to render_var -> twig_render_var() @@ -44,7 +49,7 @@ function leaveNode(\Twig_NodeInterface $node, \Twig_Environment $env) { } /** - * {@inheritdoc} + * Implements Twig_NodeVisitorInterface::getPriority(). */ function getPriority() { // We want to run before other NodeVisitors like Escape or Optimizer diff --git a/core/modules/comment/templates/comment.html.twig b/core/modules/comment/templates/comment.html.twig index c26b4b6..e8c5bb7 100644 --- a/core/modules/comment/templates/comment.html.twig +++ b/core/modules/comment/templates/comment.html.twig @@ -7,8 +7,8 @@ * - 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 following code to temporarily suppress the - * printing of a given child element: + * {{ content.field_example }}. Use the following code to temporarily suppress + * the printing of a given child element: * @code * {{ content|without('field_example') }} * @endcode 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 4f58b4d..a80598c 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Theme/TwigFilterTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/TwigFilterTest.php @@ -35,9 +35,9 @@ public static function getInfo() { } /** - * Test Twig "trans" tags. + * Test Twig "without" filter. */ - public function testTwigTransTags() { + public function testTwigWithoutFilter() { $this->drupalGet('/twig-theme-test/filter'); $elements = array( diff --git a/core/themes/bartik/templates/comment.html.twig b/core/themes/bartik/templates/comment.html.twig index cfc56f6..f66b14b 100644 --- a/core/themes/bartik/templates/comment.html.twig +++ b/core/themes/bartik/templates/comment.html.twig @@ -7,8 +7,8 @@ * - 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 following code to temporarily suppress the - * printing of a given child element: + * {{ content.field_example }}. Use the following code to temporarily suppress + * the printing of a given child element: * @code * {{ content|without('field_example') }} * @endcode diff --git a/core/themes/engines/twig/twig.engine b/core/themes/engines/twig/twig.engine index 5138041..a8bb0ce 100644 --- a/core/themes/engines/twig/twig.engine +++ b/core/themes/engines/twig/twig.engine @@ -118,7 +118,6 @@ function twig_render_template($template_file, $variables) { * @see TwigNodeVisitor */ function twig_render_var($arg) { - // Check for numeric zero. if ($arg === 0) { return 0; @@ -150,11 +149,16 @@ function twig_render_var($arg) { } /** - * Removes child elements from a renderable array. + * Removes child elements from a copy of the original array. + * + * Creates a copy of the renderable array and removes child elements by key + * specified throught filter's arguments. The copy can be printed without these + * elements. The original renderable array is still available and can be used + * to print child elements in their entirety in the twig template. * * @param array $element * The parent renderable array to exclude the child items. - * @param string[] $args,... + * @param string[] $args, ... * The string keys of $element to prevent printing. * * @return array