commit 995ab8eb83372134a9da407e7933b836946b0ecf Author: Joel Pittet Date: Wed Mar 5 21:11:18 2014 -0800 doc cleanup diff --git a/core/lib/Drupal/Core/Template/TwigExtension.php b/core/lib/Drupal/Core/Template/TwigExtension.php index c172e12..636816b 100644 --- a/core/lib/Drupal/Core/Template/TwigExtension.php +++ b/core/lib/Drupal/Core/Template/TwigExtension.php @@ -4,7 +4,8 @@ * @file * Definition of Drupal\Core\Template\TwigExtension. * - * This provides a Twig extension that registers various Drupal specific extensions to Twig. + * This provides a Twig extension that registers various Drupal specific + * extensions to Twig. * * @see \Drupal\Core\CoreServiceProvider */ @@ -12,36 +13,51 @@ namespace Drupal\Core\Template; /** - * A class for providing Twig extensions (specific Twig_NodeVisitors, filters and functions). + * A class for providing Twig extension. + * + * Specifically twig node visitors, filters and functions. * * @see \Drupal\Core\CoreServiceProvider */ class TwigExtension extends \Twig_Extension { + + /** + * {@inheritdoc} + */ 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'), + // @todo Remove URL function once http://drupal.org/node/1778610 + // is resolved. + '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'), ); } + /** + * {@inheritdoc} + */ public function getFilters() { return array( - 't' => new \Twig_Filter_Function('t'), - 'trans' => new \Twig_Filter_Function('t'), + // Translation filters. + 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'), + + // Array filters. + new \Twig_SimpleFilter('without', 'twig_without'), ); } + /** + * {@inheritdoc} + */ public function getNodeVisitors() { // The node visitor is needed to wrap all variables with // render_var -> twig_render_var() function. @@ -50,15 +66,19 @@ public function getNodeVisitors() { ); } + /** + * {@inheritdoc} + */ public function getTokenParsers() { return array( new TwigTransTokenParser(), ); } - public function getName() - { + /** + * {@inheritdoc} + */ + public function getName() { return 'drupal_core'; } } - 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..55c159e 100644 --- a/core/themes/engines/twig/twig.engine +++ b/core/themes/engines/twig/twig.engine @@ -118,18 +118,17 @@ function twig_render_template($template_file, $variables) { * @see TwigNodeVisitor */ function twig_render_var($arg) { - // Check for numeric zero. if ($arg === 0) { return 0; } - // == is true also for empty arrays + // Return early for NULL and also true for empty arrays. if ($arg == NULL) { return NULL; } - // Keep Twig_Markup objects intact to prepare for later autoescaping support + // Keep Twig_Markup objects intact to prepare for later autoescaping support. if ($arg instanceOf Twig_Markup) { return $arg; } @@ -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