|
- <?php
-
- namespace Lc\SovBundle\Twig;
-
- use Lc\SovBundle\Component\MetaComponent;
- use Twig\Extension\AbstractExtension;
- use Twig\TwigFunction;
-
- class MetaTwigExtension extends AbstractExtension
- {
- protected MetaComponent $metaComponent;
-
- public function __construct(MetaComponent $metaComponent)
- {
- $this->metaComponent = $metaComponent;
- }
-
- public function getFunctions()
- {
- return [
- new TwigFunction('meta_title', [$this, 'getMetaTitle']),
- new TwigFunction('meta_description', [$this, 'getMetaDescription']),
- new TwigFunction('opengraph_title', [$this, 'getOpengraphTitle']),
- new TwigFunction('opengraph_description', [$this, 'getOpengraphDescription']),
- new TwigFunction('opengraph_image', [$this, 'getOpengraphImage']),
- new TwigFunction('opengraph_image_url', [$this, 'getOpengraphImageUrl']),
- ];
- }
-
- public function getFilters()
- {
- return [];
- }
-
- public function getMetaTitle($entity, $title = null): ?string
- {
- return $this->metaComponent->getMetaTitle($entity, $title);
- }
-
- public function getMetaDescription($entity): ?string
- {
- return $this->metaComponent->getMetaDescription($entity);
- }
-
- public function getOpenGraphTitle($entity, $title = null): ?string
- {
- return $this->metaComponent->getOpenGraphTitle($entity, $title);
- }
-
- public function getOpenGraphDescription($entity): ?string
- {
- return $this->metaComponent->getOpenGraphDescription($entity);
- }
-
- public function getOpenGraphImage($entity): ?string
- {
- return $this->metaComponent->getOpenGraphImage($entity);
- }
-
- public function getOpenGraphImageUrl($entity): ?string
- {
- return $this->metaComponent->getOpenGraphImageUrl($entity);
- }
- }
|