diff --git a/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterTwigExtensionsPass.php b/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterTwigExtensionsPass.php index 0f1a88c..66fbb86 100644 --- a/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterTwigExtensionsPass.php +++ b/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterTwigExtensionsPass.php @@ -15,12 +15,12 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; /** - * Adds services tagged 'twig.extension' to the twig service. + * Register additional Twig extensions to the Twig service container. */ class RegisterTwigExtensionsPass implements CompilerPassInterface { /** - * Adds services tagged 'twig.extension' to the twig service. + * Adds services tagged 'twig.extension' to the Twig service container. * * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container * The container to process. @@ -45,4 +45,5 @@ public function process(ContainerBuilder $container) { $definition->addMethodCall('addExtension', array(new Reference($id))); } } + } 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 adc0556..bda959f 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 @@ -11,7 +11,7 @@ use Drupal\Core\Template\TwigReferenceFunction; /** - * A test Twig extension that adds a few simple tags. + * A test Twig extension that adds a custom function and a custom filter. */ class TestExtension extends TwigExtension { @@ -19,11 +19,13 @@ class TestExtension extends TwigExtension { * Generates a list of all Twig functions that this extension defines. * * @return array - * A key/value array that defines custom Twig functions. - * The key denotes the function name used in the tag. - * eg. {{ testfunc() }}. - * The value is a standard PHP callback that defines what the function - * does. + * A key/value array that defines custom Twig functions. The key denotes the + * function name used in the tag, e.g.: + * @code + * {{ testfunc() }} + * @endcode + * + * The value is a standard PHP callback that defines what the function does. */ public function getFunctions() { return array( @@ -37,9 +39,12 @@ public function getFunctions() { * Generates a list of all Twig filters that this extension defines. * * @return array - * A key/value array that defines custom Twig filters. - * The key denotes the filter name used in the tag. - * eg. {{ foo|testfilter }}. + * A key/value array that defines custom Twig filters. The key denotes the + * filter name used in the tag, e.g.: + * @code + * {{ foo|testfilter }} + * @endcode + * * The value is a standard PHP callback that defines what the filter does. */ public function getFilters() { @@ -61,35 +66,22 @@ public function getName() { } /** - * A Twig filter designed for testing, which replaces all instances of - * "animal" in a string with "plant". - * This is tested for in the class - * \Drupal\system\Tests\Theme\TwigExtensionTest. + * Outputs either an uppercase or lowercase test phrase. * - * @param string $string - * The string to be filtered. - * @return string - * The filtered string. - */ - public static function testFilter ($string) { - return str_replace(array('animal'), array('plant'), $string); - } - - /** - * A Twig function designed for testing, which generates either an uppercase - * or lowercase version of the phrase "The quick brown fox jumps over the - * lazy dog 123.", depending on whether or not the provided $upperCase - * parameter is truthy. If it is truthy, the result will be uppercase, and - * if not, the result will be lowercase. - * This is tested for in the class - * \Drupal\system\Tests\Theme\TwigExtensionTest. + * The function generates either an uppercase or lowercase version of the + * phrase "The quick brown fox jumps over the lazy dog 123.", depending on + * whether or not the $upperCase parameter evaluates to TRUE. If $upperCase + * evaluates to TRUE, the result will be uppercase, and if it evaluates to + * FALSE, the result will be lowercase. * - * @param boolean $upperCase + * @param bool $upperCase * (optional) Whether the result is uppercase (true) or lowercase (false). * @return string * The generated string. + * + * @see \Drupal\system\Tests\Theme\TwigExtensionTest::testTwigExtensionFunction() */ - public static function testFunction ($upperCase = FALSE) { + public static function testFunction($upperCase = FALSE) { $string = "The quick brown box jumps over the lazy dog 123."; if ($upperCase == TRUE) { return strtoupper($string); @@ -98,5 +90,19 @@ public static function testFunction ($upperCase = FALSE) { return strtolower($string); } } -} + /** + * Replaces all instances of "animal" in a string with "plant". + * + * @param string $string + * The string to be filtered. + * @return string + * The filtered string. + * + * @see \Drupal\system\Tests\Theme\TwigExtensionTest::testTwigExtensionFilter() + */ + public static function testFilter($string) { + return str_replace(array('animal'), array('plant'), $string); + } + +}