Browse Source

[Test] add HelperController test

Thomas Rabaix 13 năm trước cách đây
mục cha
commit
66ceb96398

+ 4 - 0
Admin/Admin.php

@@ -1398,6 +1398,8 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
      */
     public function getShowFieldDescriptions()
     {
+        $this->buildShow();
+
         return $this->showFieldDescriptions;
     }
 
@@ -1409,6 +1411,8 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
      */
     public function getShowFieldDescription($name)
     {
+        $this->buildShow();
+
         return $this->hasShowFieldDescription($name) ? $this->showFieldDescriptions[$name] : null;
     }
 

+ 37 - 0
Admin/AdminInterface.php

@@ -358,4 +358,41 @@ interface AdminInterface
      * @return object a new object instance
      */
     function getNewInstance();
+
+    function setUniqid($uniqId);
+
+    function getObject($id);
+
+    function setSubject($subject);
+
+    function getSubject();
+
+    /**
+     * Returns a list FieldDescription
+     *
+     * @param string $name
+     * @return \Sonata\AdminBundle\Admin\FieldDescriptionInterface
+     */
+    function getListFieldDescription($name);
+
+
+    function configure();
+
+    function update($object);
+
+    function create($object);
+
+    function delete($object);
+
+    function preUpdate($object);
+
+    function postUpdate($object);
+
+    function prePersist($object);
+
+    function postPersist($object);
+
+    function preRemove($object);
+
+    function postRemove($object);
 }

+ 82 - 51
Controller/HelperController.php

@@ -15,15 +15,44 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
 use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\Form\Util\PropertyPath;
+use Symfony\Component\HttpFoundation\Request;
+use Sonata\AdminBundle\Admin\Pool;
+use Sonata\AdminBundle\Admin\AdminHelper;
 
-class HelperController extends Controller
+class HelperController
 {
     /**
-     * @return \Sonata\AdminBundle\Admin\AdminHelper
+     * @var \Twig_Environment
      */
-    public function getAdminHelper()
+    protected $twig;
+
+    /**
+     * @var Symfony\Component\HttpFoundation\Request
+     */
+    protected $request;
+
+    /**
+     * @var \Sonata\AdminBundle\Admin\AdminHelper
+     */
+    protected $helper;
+
+    /**
+     * @var \Sonata\AdminBundle\Admin\Pool
+     */
+    protected $pool;
+
+    /**
+     * @param \Twig_Environment $twig
+     * @param \Symfony\Component\HttpFoundation\Request $request
+     * @param \Sonata\AdminBundle\Admin\Pool $pool
+     * @param \Sonata\AdminBundle\Admin\AdminHelper $helper
+     */
+    public function __construct(\Twig_Environment $twig, Request $request, Pool $pool, AdminHelper $helper)
     {
-        return $this->container->get('sonata.admin.helper');
+        $this->twig     = $twig;
+        $this->request  = $request;
+        $this->pool     = $pool;
+        $this->helper   = $helper;
     }
 
     /**
@@ -32,14 +61,13 @@ class HelperController extends Controller
      */
     public function appendFormFieldElementAction()
     {
-        $helper     = $this->getAdminHelper();
-        $request    = $this->get('request');
-        $code       = $request->query->get('code');
-        $elementId  = $request->query->get('elementId');
-        $objectId   = $request->query->get('objectId');
-        $uniqid     = $this->get('request')->query->get('uniqid');
-
-        $admin = $helper->getAdmin($code);
+        $code       = $this->request->get('code');
+        $elementId  = $this->request->get('elementId');
+        $objectId   = $this->request->get('objectId');
+        $uniqid     = $this->request->get('uniqid');
+
+        $admin      = $this->pool->getInstance($code);
+
         if ($uniqid) {
             $admin->setUniqid($uniqid);
         }
@@ -54,17 +82,17 @@ class HelperController extends Controller
         }
 
         $admin->setSubject($subject);
-        $admin->setRequest($request);
+        $admin->setRequest($this->request);
 
-        list($fieldDescription, $form) = $helper->appendFormFieldElement($admin, $elementId);
+        list($fieldDescription, $form) = $this->helper->appendFormFieldElement($admin, $elementId);
 
-        $view = $helper->getChildFormView($form->createView(), $elementId);
+        $view = $this->helper->getChildFormView($form->createView(), $elementId);
 
         // render the widget
         // todo : fix this, the twig environment variable is not set inside the extension ...
-        $twig = $this->get('twig');
-        $extension = $twig->getExtension('form');
-        $extension->initRuntime($this->get('twig'));
+
+        $extension = $this->twig->getExtension('form');
+        $extension->initRuntime($this->twig);
         $extension->setTheme($view, $admin->getFormTheme());
 
         return new Response($extension->renderWidget($view));
@@ -76,12 +104,13 @@ class HelperController extends Controller
      */
     public function retrieveFormFieldElementAction()
     {
-        $helper     = $this->getAdminHelper();
-        $code       = $this->get('request')->query->get('code');
-        $elementId  = $this->get('request')->query->get('elementId');
-        $objectId   = $this->get('request')->query->get('objectId');
-        $admin      = $helper->getAdmin($code);
-        $uniqid     = $this->get('request')->query->get('uniqid');
+
+        $code       = $this->request->get('code');
+        $elementId  = $this->request->get('elementId');
+        $objectId   = $this->request->get('objectId');
+        $uniqid     = $this->request->get('uniqid');
+
+        $admin       = $this->pool->getInstance($code);
 
         if ($objectId) {
             $subject = $admin->getModelManager()->find($admin->getClass(), $objectId);
@@ -99,15 +128,14 @@ class HelperController extends Controller
         $formBuilder = $admin->getFormBuilder($subject);
 
         $form = $formBuilder->getForm();
-        $form->bindRequest($this->get('request'));
+        $form->bindRequest($this->request);
 
-        $view = $helper->getChildFormView($form->createView(), $elementId);
+        $view = $this->helper->getChildFormView($form->createView(), $elementId);
 
         // render the widget
         // todo : fix this, the twig environment variable is not set inside the extension ...
-        $twig = $this->get('twig');
-        $extension = $twig->getExtension('form');
-        $extension->initRuntime($this->get('twig'));
+        $extension = $this->twig->getExtension('form');
+        $extension->initRuntime($this->twig);
         $extension->setTheme($view, $admin->getFormTheme());
 
         return new Response($extension->renderWidget($view));
@@ -119,11 +147,16 @@ class HelperController extends Controller
      */
     public function getShortObjectDescriptionAction()
     {
-        $code       = $this->get('request')->query->get('code');
-        $objectId   = $this->get('request')->query->get('objectId');
-        $uniqid     = $this->get('request')->query->get('uniqid');
+        $code       = $this->request->get('code');
+        $objectId   = $this->request->get('objectId');
+        $uniqid     = $this->request->get('uniqid');
+
+        $admin       = $this->pool->getInstance($code);
+
+        if (!$admin) {
+            throw new NotFoundHttpException();
+        }
 
-        $admin  = $this->container->get('sonata.admin.pool')->getInstance($code);
         if ($uniqid) {
             $admin->setUniqid($uniqid);
         }
@@ -137,7 +170,7 @@ class HelperController extends Controller
         $description = 'no description available';
         foreach (array('getAdminTitle', 'getTitle', 'getName', '__toString') as $method) {
             if (method_exists($object, $method)) {
-                $description = $object->$method();
+                $description = call_user_func(array($object, $method));
                 break;
             }
         }
@@ -153,17 +186,16 @@ class HelperController extends Controller
      */
     public function setObjectFieldValueAction()
     {
-        $field      = $this->get('request')->query->get('field');
-        $code       = $this->get('request')->query->get('code');
-        $objectId   = $this->get('request')->query->get('objectId');
-        $uniqid     = $this->get('request')->query->get('uniqid');
-        $value      = $this->get('request')->query->get('value');
-        $context    = $this->get('request')->query->get('context');
+        $field      = $this->request->get('field');
+        $code       = $this->request->get('code');
+        $objectId   = $this->request->get('objectId');
+        $value      = $this->request->get('value');
+        $context    = $this->request->get('context');
 
-        $admin  = $this->container->get('sonata.admin.pool')->getInstance($code);
+        $admin       = $this->pool->getInstance($code);
 
         // alter should be done by using a post method
-        if ($this->getRequest()->getMethod() != 'POST') {
+        if ($this->request->getMethod() != 'POST') {
             return new Response(json_encode(array('status' => 'KO', 'message' => 'Expected a POST Request')), 200, array(
                 'Content-Type' => 'application/json'
             ));
@@ -176,10 +208,6 @@ class HelperController extends Controller
             ));
         }
 
-        if ($uniqid) {
-            $admin->setUniqid($uniqid);
-        }
-
         $object = $admin->getObject($objectId);
 
         if (!$object) {
@@ -190,14 +218,18 @@ class HelperController extends Controller
 
         if ($context == 'list') {
             $fieldDescription = $admin->getListFieldDescription($field);
-        } else if ($context == 'show') {
-            $fieldDescription = $admin->getShowFieldDescription($field);
         } else {
             return new Response(json_encode(array('status' => 'KO', 'message' => 'Invalid context')), 200, array(
                 'Content-Type' => 'application/json'
             ));
         }
 
+        if (!$fieldDescription) {
+            return new Response(json_encode(array('status' => 'KO', 'message' => 'The field does not exist')), 200, array(
+                'Content-Type' => 'application/json'
+            ));
+        }
+
         if (!$fieldDescription->getOption('editable')) {
             return new Response(json_encode(array('status' => 'KO', 'message' => 'The field cannot be edit, editable option must be set to true')), 200, array(
                 'Content-Type' => 'application/json'
@@ -212,9 +244,8 @@ class HelperController extends Controller
 
         // render the widget
         // todo : fix this, the twig environment variable is not set inside the extension ...
-        $twig = $this->get('twig');
-        $extension = $twig->getExtension('sonata_admin');
-        $extension->initRuntime($this->get('twig'));
+        $extension = $this->twig->getExtension('sonata_admin');
+        $extension->initRuntime($this->twig);
 
         $content = $extension->renderListElement($object, $fieldDescription);
 

+ 8 - 0
Resources/config/core.xml

@@ -53,6 +53,14 @@
             <argument type="service" id="logger" />
             <argument type="service" id="sonata.admin.pool" />
         </service>
+
+        <!-- controller as services -->
+        <service id="sonata.admin.controller.admin" class="Sonata\AdminBundle\Controller\HelperController" scope="request">
+            <argument type="service" id="twig" />
+            <argument type="service" id="request" />
+            <argument type="service" id="sonata.admin.pool" />
+            <argument type="service" id="sonata.admin.helper" />
+        </service>
     </services>
 </container>
 

+ 5 - 5
Resources/config/routing/sonata_admin.xml

@@ -9,19 +9,19 @@
     </route>
 
     <route id="sonata_admin_retrieve_form_element" pattern="/core/get-form-field-element">
-        <default key="_controller">SonataAdminBundle:Helper:retrieveFormFieldElement</default>
+        <default key="_controller">sonata.admin.controller.admin:retrieveFormFieldElementAction</default>
     </route>
 
     <route id="sonata_admin_append_form_element" pattern="/core/append-form-field-element">
-        <default key="_controller">SonataAdminBundle:Helper:appendFormFieldElement</default>
+        <default key="_controller">sonata.admin.controller.admin:appendFormFieldElementAction</default>
     </route>
 
     <route id="sonata_admin_short_object_information" pattern="/core/get-short-object-description">
-        <default key="_controller">SonataAdminBundle:Helper:getShortObjectDescription</default>
+        <default key="_controller">sonata.admin.controller.admin:getShortObjectDescriptionAction</default>
     </route>
 
     <route id="sonata_admin_set_object_field_value" pattern="/core/set-object-field-value">
-        <default key="_controller">SonataAdminBundle:Helper:setObjectFieldValue</default>
+        <default key="_controller">sonata.admin.controller.admin:setObjectFieldValueAction</default>
     </route>
-      
+
 </routes>

+ 270 - 0
Tests/Controller/HelperControllerTest.php

@@ -0,0 +1,270 @@
+<?php
+
+/*
+ * This file is part of the Sonata package.
+ *
+ * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sonata\AdminBundle\Tests\Controller;
+
+use Sonata\AdminBundle\Admin\AdminHelper;
+use Sonata\AdminBundle\Admin\Pool;
+use Sonata\AdminBundle\Controller\HelperController;
+use \Twig_Environment as Twig;
+use \Twig_ExtensionInterface as Twig_ExtensionInterface;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Sonata\AdminBundle\Admin\AdminInterface;
+use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
+use Sonata\AdminBundle\Twig\Extension\SonataAdminExtension;
+use Symfony\Component\Form\Form;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\Form\FormBuilder;
+use Symfony\Component\Form\FormFactoryInterface;
+use Symfony\Component\Form\FormView;
+
+
+
+class AdminControllerHelper_Foo
+{
+    public function getAdminTitle()
+    {
+        return 'bar';
+    }
+
+    public function setEnabled($value)
+    {
+
+    }
+}
+
+class AdminControllerHelperTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * @expectedException Symfony\Component\HttpKernel\Exception\NotFoundHttpException
+     */
+    public function testgetShortObjectDescriptionActionInvalidAdmin()
+    {
+        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
+        $twig = new Twig;
+        $request = new Request(array(
+            'code'     => 'sonata.post.admin',
+            'objectId' => 42,
+            'uniqid'   => 'asdasd123'
+        ));
+        $pool = new Pool($container, 'title', 'logo');
+        $helper = new AdminHelper($pool);
+        $controller = new HelperController($twig, $request, $pool, $helper);
+
+        $controller->getShortObjectDescriptionAction();
+    }
+
+    public function testgetShortObjectDescriptionActionObjectDoesNotExist()
+    {
+        $admin = $this->getMock('Sonata\AdminBundle\Admin\AdminInterface');
+        $admin->expects($this->once())->method('setUniqid');
+        $admin->expects($this->once())->method('getObject')->will($this->returnValue(false));
+
+        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
+        $container->expects($this->any())->method('get')->will($this->returnValue($admin));
+
+        $twig = new Twig;
+        $request = new Request(array(
+            'code'     => 'sonata.post.admin',
+            'objectId' => 42,
+            'uniqid'   => 'asdasd123'
+        ));
+
+        $pool = new Pool($container, 'title', 'logo');
+
+        $helper = new AdminHelper($pool);
+
+        $controller = new HelperController($twig, $request, $pool, $helper);
+
+        $response = $controller->getShortObjectDescriptionAction();
+
+        $this->assertEmpty($response->getContent());
+    }
+
+    public function testgetShortObjectDescriptionActionObject()
+    {
+        $admin = $this->getMock('Sonata\AdminBundle\Admin\AdminInterface');
+        $admin->expects($this->once())->method('setUniqid');
+        $admin->expects($this->once())->method('getObject')->will($this->returnValue(new AdminControllerHelper_Foo));
+        $admin->expects($this->once())->method('generateUrl')->will($this->returnCallback(function($name, $parameters) {
+            if ($name != 'edit') {
+                return 'invalid name';
+            }
+
+            if (!isset($parameters['id'])) {
+                return 'id parameter not set';
+            }
+
+            return '/ok/url';
+        }));
+        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
+        $container->expects($this->any())->method('get')->will($this->returnValue($admin));
+
+        $twig = new Twig;
+        $request = new Request(array(
+            'code'     => 'sonata.post.admin',
+            'objectId' => 42,
+            'uniqid'   => 'asdasd123'
+        ));
+
+        $pool = new Pool($container, 'title', 'logo');
+
+        $helper = new AdminHelper($pool);
+
+        $controller = new HelperController($twig, $request, $pool, $helper);
+
+        $response = $controller->getShortObjectDescriptionAction();
+
+        $expected = '<a href="/ok/url" target="new">bar</a>';
+        $this->assertEquals($expected, $response->getContent());
+    }
+
+    public function testsetObjectFieldValueAction()
+    {
+        $object = new AdminControllerHelper_Foo;
+
+        $fieldDescription = $this->getMock('Sonata\AdminBundle\Admin\FieldDescriptionInterface');
+        $fieldDescription->expects($this->once())->method('getOption')->will($this->returnValue(true));
+
+        $admin = $this->getMock('Sonata\AdminBundle\Admin\AdminInterface');
+        $admin->expects($this->once())->method('getObject')->will($this->returnValue($object));
+        $admin->expects($this->once())->method('isGranted')->will($this->returnValue(true));
+        $admin->expects($this->once())->method('getListFieldDescription')->will($this->returnValue($fieldDescription));
+
+
+        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
+        $container->expects($this->any())->method('get')->will($this->returnValue($admin));
+
+        $adminExtension = $this->getMock('Twig_ExtensionInterface', array('renderListElement', 'initRuntime', 'getTokenParsers', 'getNodeVisitors', 'getFilters', 'getTests', 'getFunctions', 'getOperators', 'getGlobals', 'getName'));
+        $adminExtension->expects($this->once())->method('getName')->will($this->returnValue('sonata_admin'));
+        $adminExtension->expects($this->once())->method('renderListElement')->will($this->returnValue('<foo />'));
+
+        $twig = new Twig;
+        $twig->addExtension($adminExtension);
+        $request = new Request(array(
+            'code'     => 'sonata.post.admin',
+            'objectId' => 42,
+            'field'   => 'enabled',
+            'value'   => 1,
+            'context' => 'list',
+        ), array(), array(), array(), array(), array('REQUEST_METHOD' => 'POST'));
+
+        $pool = new Pool($container, 'title', 'logo');
+
+        $helper = new AdminHelper($pool);
+
+        $controller = new HelperController($twig, $request, $pool, $helper);
+
+        $response = $controller->setObjectFieldValueAction();
+
+        $this->assertEquals('{"status":"OK","content":"<foo \/>"}', $response->getContent() );
+    }
+
+    public function testappendFormFieldElementAction()
+    {
+        $object = new AdminControllerHelper_Foo;
+
+        $modelManager = $this->getMock('Sonata\AdminBundle\Model\ModelManagerInterface');
+        $modelManager->expects($this->once())->method('find')->will($this->returnValue($object));
+
+        $admin = $this->getMock('Sonata\AdminBundle\Admin\AdminInterface');
+        $admin->expects($this->once())->method('getModelManager')->will($this->returnValue($modelManager));
+        $admin->expects($this->once())->method('setRequest');
+        $admin->expects($this->once())->method('setSubject');
+
+        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
+        $container->expects($this->any())->method('get')->will($this->returnValue($admin));
+
+        $formExtension = $this->getMock('Twig_ExtensionInterface', array('renderListElement', 'initRuntime', 'getTokenParsers', 'getNodeVisitors', 'getFilters', 'getTests', 'getFunctions', 'getOperators', 'getGlobals', 'getName', 'setTheme', 'renderWidget'));
+        $formExtension->expects($this->once())->method('getName')->will($this->returnValue('form'));
+        $formExtension->expects($this->once())->method('renderWidget')->will($this->returnValue(new Response));
+        $formExtension->expects($this->once())->method('setTheme');
+
+        $twig = new Twig;
+        $twig->addExtension($formExtension);
+        $request = new Request(array(
+            'code'     => 'sonata.post.admin',
+            'objectId' => 42,
+            'field'   => 'enabled',
+            'value'   => 1,
+            'context' => 'list',
+        ), array(), array(), array(), array(), array('REQUEST_METHOD' => 'POST'));
+
+        $pool = new Pool($container, 'title', 'logo');
+
+        $dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
+
+        $form = new Form('foo', $dispatcher);
+
+        $helper = $this->getMock('Sonata\AdminBundle\Admin\AdminHelper', array('appendFormFieldElement'), array($pool));
+        $helper->expects($this->once())->method('appendFormFieldElement')->will($this->returnValue(array(
+            $this->getMock('Sonata\AdminBundle\Admin\FieldDescriptionInterface'),
+            $form
+        )));
+
+        $controller = new HelperController($twig, $request, $pool, $helper);
+        $response = $controller->appendFormFieldElementAction();
+
+        $this->isInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
+    }
+
+    public function testretrieveFormFieldElementAction()
+    {
+        $object = new AdminControllerHelper_Foo;
+
+        $modelManager = $this->getMock('Sonata\AdminBundle\Model\ModelManagerInterface');
+        $modelManager->expects($this->once())->method('find')->will($this->returnValue($object));
+
+        $formBuilder = new FormBuilder(
+            'foo',
+            $this->getMock('Symfony\Component\Form\FormFactoryInterface'),
+            $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')
+        );
+
+        $admin = $this->getMock('Sonata\AdminBundle\Admin\AdminInterface');
+        $admin->expects($this->once())->method('getModelManager')->will($this->returnValue($modelManager));
+        $admin->expects($this->once())->method('getFormBuilder')->will($this->returnValue($formBuilder));
+
+        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
+        $container->expects($this->any())->method('get')->will($this->returnValue($admin));
+
+        $formExtension = $this->getMock('Twig_ExtensionInterface', array('renderListElement', 'initRuntime', 'getTokenParsers', 'getNodeVisitors', 'getFilters', 'getTests', 'getFunctions', 'getOperators', 'getGlobals', 'getName', 'setTheme', 'renderWidget'));
+        $formExtension->expects($this->once())->method('getName')->will($this->returnValue('form'));
+        $formExtension->expects($this->once())->method('renderWidget')->will($this->returnValue(new Response));
+        $formExtension->expects($this->once())->method('setTheme');
+
+        $twig = new Twig;
+        $twig->addExtension($formExtension);
+        $request = new Request(array(
+            'code'     => 'sonata.post.admin',
+            'objectId' => 42,
+            'field'   => 'enabled',
+            'value'   => 1,
+            'context' => 'list',
+        ), array(), array(), array(), array(), array('REQUEST_METHOD' => 'POST'));
+
+        $pool = new Pool($container, 'title', 'logo');
+
+        $dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
+
+        $formView = new FormView();
+
+        $helper = $this->getMock('Sonata\AdminBundle\Admin\AdminHelper', array('getChildFormView'), array($pool));
+        $helper->expects($this->once())->method('getChildFormView')->will($this->returnValue($formView));
+
+        $controller = new HelperController($twig, $request, $pool, $helper);
+        $response = $controller->retrieveFormFieldElementAction();
+
+        $this->isInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
+    }
+}

+ 3 - 0
Tests/tests/autoload.php.dist

@@ -13,6 +13,9 @@ if (is_file($autoload)) {
         'Symfony'  => array($vendorDir.'/symfony/src'),
         'Knp'      => array($vendorDir.'/knpmenu/src'),
     ));
+    $loader->registerPrefixes(array(
+        'Twig_'            => $vendorDir.'/twig/lib',
+    ));
     $loader->register();
 
     spl_autoload_register(function($class) {

+ 2 - 1
Tests/tests/vendors.php

@@ -10,7 +10,8 @@ if (!is_dir($vendorDir)) {
 
 $deps = array(
     array('symfony', 'git://github.com/symfony/symfony.git', isset($_SERVER['SYMFONY_VERSION']) ? $_SERVER['SYMFONY_VERSION'] : 'origin/master'),
-    array('knpmenu', 'git://github.com/KnpLabs/KnpMenu.git', 'origin/master')
+    array('knpmenu', 'git://github.com/KnpLabs/KnpMenu.git', 'origin/master'),
+    array('twig', 'git://github.com/fabpot/Twig.git', '1.3.0'),
 );
 
 foreach ($deps as $dep) {

+ 2 - 1
Twig/Extension/SonataAdminExtension.php

@@ -173,7 +173,8 @@ class SonataAdminExtension extends \Twig_Extension
         return $this->output($fieldDescription, $template, array(
             'field_description' => $fieldDescription,
             'object'            => $object,
-            'value'             => $value
+            'value'             => $value,
+            'admin'             => $fieldDescription->getAdmin()
         ));
     }