You are here

Truncate.php in Twig Extender 8.2

File

src/Plugin/TwigPlugin/Truncate.php
View source
<?php

namespace Drupal\twig_extender\Plugin\TwigPlugin;

use Drupal\twig_extender\Plugin\Twig\TwigPluginBase;
use Drupal\Component\Utility\Unicode;

/**
 * Example plugin for truncate.
 *
 * @TwigPlugin(
 *   id = "twig_extender_truncate",
 *   label = @Translation("Truncate string"),
 *   type = "filter",
 *   name = "truncate",
 *   function = "trunc"
 * )
 */
class Truncate extends TwigPluginBase {

  /**
   * Implement truncate filter.
   */
  public function trunc($string, $maxLength, $wordsafe = FALSE, $addEllipsis = FALSE, $minWordsafeLength = 1) {
    return Unicode::truncate($string, $maxLength, $wordsafe, $addEllipsis, $minWordsafeLength);
  }

}

Classes

Namesort descending Description
Truncate Example plugin for truncate.