class Typogrify in Typogrify 8
Same name in this branch
- 8 src/Typogrify.php \Drupal\typogrify\Typogrify
- 8 src/TwigExtension/Typogrify.php \Drupal\typogrify\TwigExtension\Typogrify
A class providing Drupal Twig extensions.
This provides a Twig extension that applies the filters provided by the Typogrify module.
Hierarchy
- class \Drupal\typogrify\TwigExtension\Typogrify extends \Drupal\typogrify\TwigExtension\Twig_Extension
Expanded class hierarchy of Typogrify
2 string references to 'Typogrify'
1 service uses Typogrify
File
- src/
TwigExtension/ Typogrify.php, line 14
Namespace
Drupal\typogrify\TwigExtensionView source
class Typogrify extends \Twig_Extension {
/**
* {@inheritdoc}
*/
public function getFilters() {
return [
new \Twig_SimpleFilter('typogrify', [
$this,
'filter',
], [
'is_safe' => [
'html',
],
]),
];
}
/**
* Filter text by Typogrify.
*
* @param string $text
* The text to be processed.
* @param string[] $options
* Filters to be used for filtering. If empty, all filters will be used.
* Possible values: amp, widont, smartypants, caps, initial_quotes, dash.
*
* @return string
* The filtered string.
*/
public static function filter($text, array $options = []) {
if (empty($options)) {
return TypogrifyBase::filter($text);
}
if (in_array('amp', $options)) {
$text = TypogrifyBase::amp($text);
}
if (in_array('widont', $options)) {
$text = TypogrifyBase::widont($text);
}
if (in_array('smartypants', $options)) {
$text = SmartyPants::process($text);
}
if (in_array('caps', $options)) {
$text = TypogrifyBase::caps($text);
}
if (in_array('initial_quotes', $options)) {
$text = TypogrifyBase::initialQuotes($text);
}
if (in_array('dash', $options)) {
$text = TypogrifyBase::dash($text);
}
return $text;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Typogrify:: |
public static | function | Filter text by Typogrify. | |
Typogrify:: |
public | function |