You are here

class DateApStyle in AP Style Date 8

Custom twig filter to display dates as AP Style.

Hierarchy

  • class \Drupal\date_ap_style\TwigExtension\DateApStyle extends \Twig\Extension\AbstractExtension

Expanded class hierarchy of DateApStyle

1 string reference to 'DateApStyle'
date_ap_style.services.yml in ./date_ap_style.services.yml
date_ap_style.services.yml
1 service uses DateApStyle
date_ap_style.twig_extension in ./date_ap_style.services.yml
Drupal\date_ap_style\TwigExtension\DateApStyle

File

src/TwigExtension/DateApStyle.php, line 12

Namespace

Drupal\date_ap_style\TwigExtension
View source
class DateApStyle extends AbstractExtension {

  /**
   * The date formatter.
   *
   * @var \Drupal\date_ap_style\ApStyleDateFormatter
   */
  protected $apStyleDateFormatter;

  /**
   * Constructs \Drupal\Core\Template\TwigExtension.
   *
   * @param \Drupal\date_ap_style\ApStyleDateFormatter $date_formatter
   *   The date formatter.
   */
  public function __construct(ApStyleDateFormatter $date_formatter) {
    $this->apStyleDateFormatter = $date_formatter;
  }

  /**
   * 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 [
      new TwigFilter('ap_style', [
        $this->apStyleDateFormatter,
        'formatTimestamp',
      ]),
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DateApStyle::$apStyleDateFormatter protected property The date formatter.
DateApStyle::getFilters public function Generates a list of all Twig filters that this extension defines.
DateApStyle::__construct public function Constructs \Drupal\Core\Template\TwigExtension.