DateApStyle.php in AP Style Date 8
Namespace
Drupal\date_ap_style\TwigExtensionFile
src/TwigExtension/DateApStyle.phpView 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
Name | Description |
---|---|
DateApStyle | Custom twig filter to display dates as AP Style. |