123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace Sonata\AdminBundle\Twig;
- use Sonata\AdminBundle\Admin\Pool;
- use Symfony\Component\DependencyInjection\ContainerInterface;
- class GlobalVariables
- {
-
- protected $container;
-
- protected $adminPool;
-
- public function __construct($adminPool)
- {
-
- if ($adminPool instanceof ContainerInterface) {
- @trigger_error(
- 'Using an instance of Symfony\Component\DependencyInjection\ContainerInterface is deprecated since
- version 3.5 and will be removed in 4.0. Use Sonata\AdminBundle\Admin\Pool instead.',
- E_USER_DEPRECATED
- );
- $this->adminPool = $adminPool->get('sonata.admin.pool');
- } elseif ($adminPool instanceof Pool) {
- $this->adminPool = $adminPool;
- } else {
- throw new \InvalidArgumentException(
- '$adminPool should be an instance of Sonata\AdminBundle\Admin\Pool'
- );
- }
- }
-
- public function getAdminPool()
- {
- return $this->adminPool;
- }
-
- public function url($code, $action, $parameters = array(), $absolute = false)
- {
- list($action, $code) = $this->getCodeAction($code, $action);
- return $this->getAdminPool()->getAdminByAdminCode($code)->generateUrl($action, $parameters, $absolute);
- }
-
- public function objectUrl($code, $action, $object, $parameters = array(), $absolute = false)
- {
- list($action, $code) = $this->getCodeAction($code, $action);
- return $this->getAdminPool()->getAdminByAdminCode($code)->generateObjectUrl($action, $object, $parameters, $absolute);
- }
-
- private function getCodeAction($code, $action)
- {
- if ($pipe = strpos($code, '|')) {
-
-
- $action = $code.'.'.$action;
- $code = substr($code, 0, $pipe);
- }
- return array($action, $code);
- }
- }
|