GlobalVariables.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /*
  3. * This file is part of the Sonata package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\AdminBundle\Twig;
  11. use Symfony\Component\DependencyInjection\ContainerInterface;
  12. use Sonata\AdminBundle\Admin\Pool;
  13. /**
  14. * GlobalVariables
  15. *
  16. * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  17. */
  18. class GlobalVariables
  19. {
  20. protected $container;
  21. /**
  22. * @param ContainerInterface $container
  23. */
  24. public function __construct(ContainerInterface $container)
  25. {
  26. $this->container = $container;
  27. }
  28. /**
  29. * @return Pool
  30. */
  31. public function getAdminPool()
  32. {
  33. return $this->container->get('sonata.admin.pool');
  34. }
  35. /**
  36. * @param string $code
  37. * @param string $action
  38. * @param array $parameters
  39. * @param mixed $absolute
  40. *
  41. * @return string
  42. */
  43. public function url($code, $action, $parameters = array(), $absolute = false)
  44. {
  45. if ($pipe = strpos('|', $code)) {
  46. // convert code=sonata.page.admin.page|sonata.page.admin.snapshot, action=list
  47. // to => sonata.page.admin.page|sonata.page.admin.snapshot.list
  48. $action = $code.'.'.$action;
  49. $code = substr($code, 0, $pipe);
  50. }
  51. return $this->getAdminPool()->getAdminByAdminCode($code)->generateUrl($action, $parameters, $absolute);
  52. }
  53. }