Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

64 lines
1.8KB

  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('meta_title', [$this, 'getMetaTitle']),
  17. new TwigFunction('meta_description', [$this, 'getMetaDescription']),
  18. new TwigFunction('opengraph_title', [$this, 'getOpengraphTitle']),
  19. new TwigFunction('opengraph_description', [$this, 'getOpengraphDescription']),
  20. new TwigFunction('opengraph_image', [$this, 'getOpengraphImage']),
  21. new TwigFunction('opengraph_image_url', [$this, 'getOpengraphImageUrl']),
  22. ];
  23. }
  24. public function getFilters()
  25. {
  26. return [];
  27. }
  28. public function getMetaTitle($entity, $title = null): ?string
  29. {
  30. return $this->metaComponent->getMetaTitle($entity, $title);
  31. }
  32. public function getMetaDescription($entity): ?string
  33. {
  34. return $this->metaComponent->getMetaDescription($entity);
  35. }
  36. public function getOpenGraphTitle($entity, $title = null): ?string
  37. {
  38. return $this->metaComponent->getOpenGraphTitle($entity, $title);
  39. }
  40. public function getOpenGraphDescription($entity): ?string
  41. {
  42. return $this->metaComponent->getOpenGraphDescription($entity);
  43. }
  44. public function getOpenGraphImage($entity): ?string
  45. {
  46. return $this->metaComponent->getOpenGraphImage($entity);
  47. }
  48. public function getOpenGraphImageUrl($entity): ?string
  49. {
  50. return $this->metaComponent->getOpenGraphImageUrl($entity);
  51. }
  52. }