You are here

DateApStyle.php in AP Style Date 8

File

src/TwigExtension/DateApStyle.php
View source
<?php

namespace Drupal\date_ap_style\TwigExtension;

use Drupal\date_ap_style\ApStyleDateFormatter;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;

/**
 * Custom twig filter to display dates as AP Style.
 */
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',
      ]),
    ];
  }

}

Classes

Namesort descending Description
DateApStyle Custom twig filter to display dates as AP Style.