You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.6KB

  1. <?php
  2. namespace Lc\SovBundle\Twig;
  3. use Lc\SovBundle\Component\MetaComponent;
  4. use Twig\Extension\AbstractExtension;
  5. use Twig\TwigFunction;
  6. class MetaTwigExtension extends AbstractExtension
  7. {
  8. protected MetaComponent $metaComponent;
  9. public function __construct(MetaComponent $metaComponent)
  10. {
  11. $this->metaComponent = $metaComponent;
  12. }
  13. public function getFunctions()
  14. {
  15. return [
  16. new TwigFunction('sov_meta_title', [$this, 'getMetaTitle']),
  17. new TwigFunction('sov_meta_description', [$this, 'getMetaDescription']),
  18. new TwigFunction('sov_opengraph_title', [$this, 'getOpengraphTitle']),
  19. new TwigFunction('sov_opengraph_description', [$this, 'getOpengraphDescription']),
  20. new TwigFunction('sov_opengraph_image', [$this, 'getOpengraphImage']),
  21. ];
  22. }
  23. public function getFilters()
  24. {
  25. return [];
  26. }
  27. public function getMetaTitle($entity): ?string
  28. {
  29. return $this->metaComponent->getMetaTitle($entity);
  30. }
  31. public function getMetaDescription($entity): ?string
  32. {
  33. return $this->metaComponent->getMetaDescription($entity);
  34. }
  35. public function getOpenGraphTitle($entity): ?string
  36. {
  37. return $this->metaComponent->getOpenGraphTitle($entity);
  38. }
  39. public function getOpenGraphDescription($entity): ?string
  40. {
  41. return $this->metaComponent->getOpenGraphDescription($entity);
  42. }
  43. public function getOpenGraphImage($entity): ?string
  44. {
  45. return $this->metaComponent->getOpenGraphImage($entity);
  46. }
  47. }