requestStack = $requestStack; $this->dateSettings = $dateSettings; } /** * {@inheritdoc} */ public function getFilters() { return [ new TwigFilter('month_name', [$this, 'monthName']), new TwigFilter('date_short', [$this, 'dateShort']), ]; } /** * @return string */ protected function getLocale() { return $this->requestStack->getCurrentRequest()->getLocale(); } /** * @param array $context * @param DateTime $date * @return string */ public function dateShort(DateTime $date) { $locale = $this->getLocale(); $format = self::FALLBACK_SHORT; if (isset($this->dateSettings[$locale]['date_short'])) { $format = $this->dateSettings[$locale]['date_short']; } return date_format($date, $format); } /** * @param \DateTime $date * @return string */ public function monthName(\DateTime $date) { return 'month.' . $date->format('n'); } }