src/Zicht/Bundle/AdminBundle/Twig/Extension.php
public function adminUrl($subject, $action, $parameters = array())
    {
        if (is_object($subject)) {
            $className = get_class($subject);
        } elseif (is_string($subject)) {
            $className = $subject;
            if (strpos($className, ':') !== false) {
                list($namespace, $entity) = explode(':', $className);
                $className = $this->doctrine->getAliasNamespace($namespace) . '\\' . $entity;
            }
        } else {
            throw new InvalidArgumentException("Unsupported subject, need either an object or a string");
        }

        /** @var $admin \Sonata\AdminBundle\Admin\Admin */
        $admin = $this->sonata->getAdminByClass($className);
        if (!$admin) {
            // assume the string is an admincode.
            $admin = $this->sonata->getAdminByAdminCode($className);
        }

        if (!$admin) {
            throw new InvalidArgumentException("No admin found for {$className}");
        }
        if (is_object($subject)) {
            return $admin->generateObjectUrl($action, $subject, $parameters);
        } else {
            return $admin->generateUrl($action, $parameters);
        }
    }
public function adminUrl($subject, $action, $parameters = array())
    {
        if (is_object($subject)) {
            $className = get_class($subject);
        } elseif (is_string($subject)) {
            $className = $subject;
            if (strpos($className, ':') !== false) {
                list($namespace, $entity) = explode(':', $className);
                $className = $this->doctrine->getAliasNamespace($namespace) . '\\' . $entity;
            }
        } else {
            throw new InvalidArgumentException("Unsupported subject, need either an object or a string");
        }

        /** @var $admin \Sonata\AdminBundle\Admin\Admin */
        $admin = $this->sonata->getAdminByClass($className);
        if (!$admin) {
            // assume the string is an admincode.
            $admin = $this->sonata->getAdminByAdminCode($className);
        }

        if (!$admin) {
            throw new InvalidArgumentException("No admin found for {$className}");
        }
        if (is_object($subject)) {
            return $admin->generateObjectUrl($action, $subject, $parameters);
        } else {
            return $admin->generateUrl($action, $parameters);
        }
    }
public function adminUrl ( $ subject , $ action , $ parameters = array ( ) ) { if ( is_object ( $ subject ) ) { $ className = get_class ( $ subject ) ; } elseif ( is_string ( $ subject ) ) { $ className = $ subject ; if ( strpos ( $ className , ':' ) !== false ) { list ( $ namespace , $ entity ) = explode ( ':' , $ className ) ; $ className = $ this -> doctrine -> getAliasNamespace ( $ namespace ) . '\\' . $ entity ; } } else { throw new InvalidArgumentException ( "Unsupported subject, need either an object or a string" ) ; } /** @var $admin \Sonata\AdminBundle\Admin\Admin */ $ admin = $ this -> sonata -> getAdminByClass ( $ className ) ; if ( ! $ admin ) { // assume the string is an admincode. $ admin = $ this -> sonata -> getAdminByAdminCode ( $ className ) ; } if ( ! $ admin ) { throw new InvalidArgumentException ( "No admin found for {$className}" ) ; } if ( is_object ( $ subject ) ) { return $ admin -> generateObjectUrl ( $ action , $ subject , $ parameters ) ; } else { return $ admin -> generateUrl ( $ action , $ parameters ) ; } }
Render an url to a sonata admin

@param mixed $subject
@param string $action
@param array $parameters
@return string
@throws InvalidArgumentException
Render an url to a sonata admin