You are here

class Typogrify in Typogrify 8

Same name in this branch
  1. 8 src/Typogrify.php \Drupal\typogrify\Typogrify
  2. 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'
typogrify.info.yml in ./typogrify.info.yml
typogrify.info.yml
typogrify.services.yml in ./typogrify.services.yml
typogrify.services.yml
1 service uses Typogrify
typogrify.twig_extension in ./typogrify.services.yml
Drupal\typogrify\TwigExtension\Typogrify

File

src/TwigExtension/Typogrify.php, line 14

Namespace

Drupal\typogrify\TwigExtension
View 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

Namesort descending Modifiers Type Description Overrides
Typogrify::filter public static function Filter text by Typogrify.
Typogrify::getFilters public function