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.

MetaTwigExtension.php 1.8KB

3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. }