class TestExtension in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/tests/modules/twig_extension_test/src/TwigExtension/TestExtension.php \Drupal\twig_extension_test\TwigExtension\TestExtension
A test Twig extension that adds a custom function and a custom filter.
Hierarchy
- class \Drupal\Core\Template\TwigExtension extends \Drupal\Core\Template\Twig_Extension
- class \Drupal\twig_extension_test\TwigExtension\TestExtension
Expanded class hierarchy of TestExtension
1 string reference to 'TestExtension'
- twig_extension_test.services.yml in core/
modules/ system/ tests/ modules/ twig_extension_test/ twig_extension_test.services.yml - core/modules/system/tests/modules/twig_extension_test/twig_extension_test.services.yml
1 service uses TestExtension
- twig_extension_test.twig.test_extension in core/
modules/ system/ tests/ modules/ twig_extension_test/ twig_extension_test.services.yml - Drupal\twig_extension_test\TwigExtension\TestExtension
File
- core/
modules/ system/ tests/ modules/ twig_extension_test/ src/ TwigExtension/ TestExtension.php, line 15 - Contains \Drupal\twig_extension_test\TwigExtension\TestExtension.
Namespace
Drupal\twig_extension_test\TwigExtensionView source
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, e.g.:
* @code
* {{ testfunc() }}
* @endcode
*
* The value is a standard PHP callback that defines what the function does.
*/
public function getFunctions() {
return array(
'testfunc' => new \Twig_Function_Function(array(
'Drupal\\twig_extension_test\\TwigExtension\\TestExtension',
'testFunction',
)),
);
}
/**
* 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, e.g.:
* @code
* {{ foo|testfilter }}
* @endcode
*
* The value is a standard PHP callback that defines what the filter does.
*/
public function getFilters() {
return array(
'testfilter' => new \Twig_Filter_Function(array(
'Drupal\\twig_extension_test\\TwigExtension\\TestExtension',
'testFilter',
)),
);
}
/**
* Gets a unique identifier for this Twig extension.
*
* @return string
* A unique identifier for this Twig extension.
*/
public function getName() {
return 'twig_extension_test.test_extension';
}
/**
* Outputs either an uppercase or lowercase test phrase.
*
* 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 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) {
$string = "The quick brown box jumps over the lazy dog 123.";
if ($upperCase == TRUE) {
return strtoupper($string);
}
else {
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);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TestExtension:: |
public | function |
Generates a list of all Twig filters that this extension defines. Overrides TwigExtension:: |
|
TestExtension:: |
public | function |
Generates a list of all Twig functions that this extension defines. Overrides TwigExtension:: |
|
TestExtension:: |
public | function |
Gets a unique identifier for this Twig extension. Overrides TwigExtension:: |
|
TestExtension:: |
public static | function | Replaces all instances of "animal" in a string with "plant". | |
TestExtension:: |
public static | function | Outputs either an uppercase or lowercase test phrase. | |
TwigExtension:: |
protected | property | The date formatter. | |
TwigExtension:: |
protected | property | The renderer. | |
TwigExtension:: |
protected | property | The theme manager. | |
TwigExtension:: |
protected | property | The URL generator. | |
TwigExtension:: |
public | function | Attaches an asset library to the template, and hence to the response. | |
TwigExtension:: |
public | function | Overrides twig_escape_filter(). | |
TwigExtension:: |
public | function | Provides a placeholder wrapper around ::escapeFilter. | |
TwigExtension:: |
public | function | Gets the name of the active theme. | |
TwigExtension:: |
public | function | Gets the path of the active theme. | |
TwigExtension:: |
public | function | Gets a rendered link from an url object. | |
TwigExtension:: |
public | function | ||
TwigExtension:: |
public | function | Generates a URL path given a route name and parameters. | |
TwigExtension:: |
public | function | ||
TwigExtension:: |
public | function | Generates an absolute URL given a route name and parameters. | |
TwigExtension:: |
public | function | Determines at compile time whether the generated URL will be safe. | |
TwigExtension:: |
public | function | Wrapper around render() for twig printed output. | |
TwigExtension:: |
public | function | Joins several strings together safely. | |
TwigExtension:: |
public | function | Sets the date formatter. | |
TwigExtension:: |
public | function | Sets the URL generator. | |
TwigExtension:: |
public | function | Sets the theme manager. | |
TwigExtension:: |
public | function | Sets the URL generator. | |
TwigExtension:: |
public | function | Constructs \Drupal\Core\Template\TwigExtension. |