vendor/perfectneeds/content-multi-lang-bundle/Twig/VarsRuntime.php line 33

Open in your IDE?
  1. <?php
  2. namespace PN\ContentBundle\Twig;
  3. use PN\ContentBundle\Service\DynamicContentService;
  4. use Symfony\Component\Routing\RouterInterface;
  5. use Twig\Extension\RuntimeExtensionInterface;
  6. /**
  7. * @author Peter Nassef <peter.nassef@gmail.com>
  8. * @version 1.0
  9. */
  10. class VarsRuntime implements RuntimeExtensionInterface
  11. {
  12. private RouterInterface $router;
  13. private DynamicContentService $dynamicContentService;
  14. public function __construct(RouterInterface $router, DynamicContentService $dynamicContentService)
  15. {
  16. $this->router = $router;
  17. $this->dynamicContentService = $dynamicContentService;
  18. }
  19. /**
  20. * get DynamicContentAttribute by ID
  21. *
  22. * @param int $dynamicContentAttributeId
  23. * @return string
  24. * @example {{ getDCA(11) }}
  25. *
  26. */
  27. public function getDynamicContentAttribute(int $dynamicContentAttributeId, $showEditBtn = true): string
  28. {
  29. return $this->dynamicContentService->getDynamicContentAttribute($dynamicContentAttributeId, $showEditBtn);
  30. }
  31. /**
  32. * edit DynamicContentAttribute by ID
  33. *
  34. * @param int $dynamicContentAttributeId
  35. * @return string
  36. * @example {{ editDCA(11) }}
  37. *
  38. */
  39. public function editDynamicContentAttribute(int $dynamicContentAttributeId): string
  40. {
  41. return $this->dynamicContentService->showEditBtn($dynamicContentAttributeId);
  42. }
  43. public function openGalleryBtn($postId): string
  44. {
  45. $url = $this->router->generate("post_images_popup", ['id' => $postId]);
  46. return '<a href="' . $url . '" target="popup" onclick="window.open(\'' . $url . '\',\'popup\',\'width=600,height=600\'); return false;" class="btn btn-default">Open Gallery</a>';
  47. }
  48. }