* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Sonata\AdminBundle\Twig; use Symfony\Component\DependencyInjection\ContainerInterface; use Sonata\AdminBundle\Admin\Pool; /** * GlobalVariables * * @author Thomas Rabaix */ class GlobalVariables { protected $container; /** * @param ContainerInterface $container */ public function __construct(ContainerInterface $container) { $this->container = $container; } /** * @return Pool */ public function getAdminPool() { return $this->container->get('sonata.admin.pool'); } /** * @param string $code * @param string $action * @param array $parameters * @param mixed $absolute * * @return string */ public function url($code, $action, $parameters = array(), $absolute = false) { if ($pipe = strpos('|', $code)) { // convert code=sonata.page.admin.page|sonata.page.admin.snapshot, action=list // to => sonata.page.admin.page|sonata.page.admin.snapshot.list $action = $code.'.'.$action; $code = substr($code, 0, $pipe); } return $this->getAdminPool()->getAdminByAdminCode($code)->generateUrl($action, $parameters, $absolute); } }