entityURLGenerator = $entityURLGenerator; $this->cache = $cache; $this->serializer = $serializer; $this->treeBuilder = $treeBuilder; } public function getFilters() { return [ new TwigFilter('entityURL', [$this, 'generateEntityURL']), new TwigFilter('bbCode', [$this, 'parseBBCode'], ['pre_escape' => 'html', 'is_safe' => ['html']]), ]; } public function getFunctions() { return [ new TwigFunction('generateTreeData', [$this, 'treeData']) ]; } public function treeData(DBElement $element, string $type = 'newEdit') : string { $tree = $this->treeBuilder->typeToTree(get_class($element), $type, $element); return $this->serializer->serialize($tree, 'json', ['skip_null_values' => true]); } 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(); } }