entityURLGenerator = $entityURLGenerator; $this->cache = $cache; } public function getFilters() { return [ new TwigFilter('entityURL', [$this, 'generateEntityURL']), new TwigFilter('bbCode', [$this, 'parseBBCode'], ['pre_escape' => 'html', 'is_safe' => ['html']]), ]; } public function generateEntityURL(DBElement $entity, string $method = 'info'): string { return $this->entityURLGenerator->getURL($entity, $method); } public function parseBBCode(string $bbcode): string { if ('' === $bbcode) { return ''; } $item = $this->cache->getItem('bbcode_'.md5($bbcode)); if (!$item->isHit()) { $xml = TextFormatter::parse($bbcode); $item->set(TextFormatter::render($xml)); $this->cache->save($item); } return $item->get(); } }