Ver código fonte

Refactor the show action, rename view => show, fix bug and missing implementation

Thomas Rabaix 14 anos atrás
pai
commit
6b2e10a4b4

+ 117 - 190
Admin/Admin.php

@@ -22,6 +22,7 @@ use Symfony\Component\Security\Acl\Model\DomainObjectInterface;
 use Sonata\AdminBundle\Form\FormMapper;
 use Sonata\AdminBundle\Datagrid\ListMapper;
 use Sonata\AdminBundle\Datagrid\DatagridMapper;
+use Sonata\AdminBundle\Show\ShowMapper;
 
 use Sonata\AdminBundle\Admin\Pool;
 use Sonata\AdminBundle\Validator\ErrorElement;
@@ -29,7 +30,7 @@ use Sonata\AdminBundle\Validator\ErrorElement;
 use Sonata\AdminBundle\Builder\FormContractorInterface;
 use Sonata\AdminBundle\Builder\ListBuilderInterface;
 use Sonata\AdminBundle\Builder\DatagridBuilderInterface;
-use Sonata\AdminBundle\Builder\ViewBuilderInterface;
+use Sonata\AdminBundle\Builder\ShowBuilderInterface;
 
 use Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface;
 use Sonata\AdminBundle\Route\RouteCollection;
@@ -48,32 +49,47 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
     protected $class;
 
     /**
-     * The list FieldDescription constructed from the $list property
-     * and the configureListField method
+     * The list collection
+     *
+     * @var array
+     */
+    protected $list;
+
+    /**
+     * The list FieldDescription constructed from the configureListField method
      *
      * @var array
      */
     protected $listFieldDescriptions = array();
 
+    protected $show;
+
     /**
-     * The view FieldDescription constructed from the $view property
-     * and the configureListField method
+     * The show FieldDescription constructed from the configureShowField method
      *
      * @var array
      */
-    protected $viewFieldDescriptions = array();
+    protected $showFieldDescriptions = array();
+
+    /**
+     * @var Form
+     */
+    protected $form;
 
     /**
-     * The list FieldDescription constructed from the $list property
-     * and the the configureFormField method
+     * The list FieldDescription constructed from the configureFormField method
      *
      * @var array
      */
     protected $formFieldDescriptions = array();
 
     /**
-     * The filter FieldDescription constructed from the $list property
-     * and the the configureFilterField method
+     * @var DatagridInterface
+     */
+    protected $filter;
+
+    /**
+     * The filter FieldDescription constructed from the configureFilterField method
      *
      * @var array
      */
@@ -270,9 +286,9 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
     /**
      * The related view builder
      *
-     * @var \Sonata\AdminBundle\View\ViewBuilderInterface
+     * @var \Sonata\AdminBundle\View\ShowBuilderInterface
      */
-    protected $viewBuilder;
+    protected $showBuilder;
 
     /**
      * The related datagrid builder
@@ -316,10 +332,6 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
     protected $menu;
 
     protected $loaded = array(
-        'form_fields'   => false,
-        'form_groups'   => false,
-        'list_fields'   => false,
-        'filter_fields' => false,
         'view_fields'   => false,
         'view_groups'   => false,
         'routes'        => false,
@@ -359,7 +371,7 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
      *
      * @param DatagridMapper
      */
-    protected function configureViewFields(DatagridMapper $filter)
+    protected function configureShowField(ShowMapper $filter)
     {
 
     }
@@ -463,20 +475,31 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
      *
      * @return void
      */
-    protected function buildViewFieldDescriptions()
+    protected function buildShow()
     {
-        if ($this->loaded['view_fields']) {
+        if ($this->show) {
             return;
         }
 
-        $this->loaded['view_fields'] = true;
+        $collection = new FieldDescriptionCollection();
+        $mapper = new ShowMapper($this->showBuilder, $collection, $this);
+
+        $this->configureShowField($mapper);
+
+        if (!$this->viewGroups) {
+            $this->viewGroups = array(
+                false => array('fields' => array_keys($this->getShowFieldDescriptions()))
+            );
+        }
 
-        // normalize field
-        foreach ($this->viewFieldDescriptions as $fieldDescription) {
-            $this->getViewBuilder()->fixFieldDescription($this, $fieldDescription);
+        // normalize array
+        foreach ($this->viewGroups as $name => $group) {
+            if (!isset($this->viewGroups[$name]['collapsed'])) {
+                $this->viewGroups[$name]['collapsed'] = false;
+            }
         }
 
-        return $this->viewFieldDescriptions;
+        $this->show = $collection;
     }
 
     /**
@@ -484,20 +507,17 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
      *
      * @return void
      */
-    protected function buildListFieldDescriptions()
+    protected function buildList()
     {
-        if ($this->loaded['list_fields']) {
+        if ($this->list) {
             return;
         }
 
-        $this->loaded['list_fields'] = true;
+        $this->list = $this->getListBuilder()->getBaseList();
 
-        // normalize field
-        foreach ($this->listFieldDescriptions as $fieldDescription) {
-            $this->getListBuilder()->fixFieldDescription($this, $fieldDescription);
-        }
+        $mapper = new ListMapper($this->getListBuilder(), $this->list, $this);
 
-        if (!isset($this->listFieldDescriptions['_batch']) && count($this->getBatchActions()) > 0) {
+        if (count($this->getBatchActions()) > 0) {
             $fieldDescription = $this->modelManager->getNewFieldDescriptionInstance($this->getClass(), 'batch', array(
                 'label'    => 'batch',
                 'code'     => '_batch',
@@ -507,10 +527,11 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
 
             $fieldDescription->setAdmin($this);
             $fieldDescription->setTemplate('SonataAdminBundle:CRUD:list__batch.html.twig');
-            $this->listFieldDescriptions = array( '_batch' => $fieldDescription ) + $this->listFieldDescriptions;
+
+            $mapper->add($fieldDescription);
         }
 
-        return $this->listFieldDescriptions;
+        $this->configureListFields($mapper);
     }
 
     /**
@@ -544,14 +565,12 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
      *
      * @return void
      */
-    public function buildFilterFieldDescriptions()
+    public function buildDatagrid()
     {
-        if ($this->loaded['filter_fields']) {
+        if ($this->datagrid) {
             return;
         }
 
-        $this->loaded['filter_fields'] = true;
-
         // ok, try to limit to add parent filter
         if ($this->getParentAssociationMapping()) {
             $fieldDescription = $this->getModelManager()->getParentFieldDescription($this->getParentAssociationMapping(), $this->getClass());
@@ -571,7 +590,6 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
         $mapper = new DatagridMapper($this->getDatagridBuilder(), $this->datagrid, $this);
 
         // build the datagrid filter
-        $this->buildFilterFieldDescriptions();
         $this->configureDatagridFilters($mapper);
 
         foreach ($this->getFilterFieldDescriptions() as $fieldDescription) {
@@ -595,21 +613,34 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
      *
      * @return void
      */
-    protected function buildFormFieldDescriptions()
+    protected function buildForm()
     {
-        if ($this->loaded['form_fields']) {
+        if ($this->form) {
             return;
         }
 
-        $this->loaded['form_fields'] = true;
+        // append parent object if any
+        // todo : clean the way the Admin class can retrieve set the object
+        if ($this->isChild() && $this->getParentAssociationMapping()) {
+            $parent = $this->getParent()->getObject($this->request->get($this->getParent()->getIdParameter()));
+
+            $propertyPath = new \Symfony\Component\Form\Util\PropertyPath($this->getParentAssociationMapping());
+            $propertyPath->setValue($object, $parent);
+        }
 
-        foreach ($this->formFieldDescriptions as $name => &$fieldDescription) {
+        $this->form = $this->getFormBuilder()->getForm();
 
-            $this->getFormContractor()->fixFieldDescription($this, $fieldDescription);
+        // configure the form group thing
+        if (!$this->formGroups) {
+            $this->formGroups = array(
+                false => array('fields' => array_keys($this->formFieldDescriptions))
+            );
+        }
 
-            // unset the identifier field as it is not required to update an object
-            if ($fieldDescription->isIdentifier()) {
-                unset($this->formFieldDescriptions[$name]);
+        // normalize array
+        foreach ($this->formGroups as $name => $group) {
+            if (!isset($this->formGroups[$name]['collapsed'])) {
+                $this->formGroups[$name]['collapsed'] = false;
             }
         }
     }
@@ -776,7 +807,7 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
         $collection->add('batch');
         $collection->add('edit', $this->getRouterIdParameter().'/edit');
         $collection->add('delete', $this->getRouterIdParameter().'/delete');
-        $collection->add('view', $this->getRouterIdParameter().'/view');
+        $collection->add('show', $this->getRouterIdParameter().'/show');
 
         // add children urls
         foreach ($this->getChildren() as $children) {
@@ -892,9 +923,9 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
      *
      * @return string the view template
      */
-    public function getViewTemplate()
+    public function getShowTemplate()
     {
-        return 'SonataAdminBundle:CRUD:view.html.twig';
+        return 'SonataAdminBundle:CRUD:show.html.twig';
     }
 
     /**
@@ -909,21 +940,10 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
 
     /**
      * @param Object $object
-     * @param array $options
      * @return \Symfony\Component\Form\FormBuilder the form builder
      */
-    public function getFormBuilder($object = null, $options = array())
+    public function getFormBuilder()
     {
-        if (!$object) {
-            $object = $this->getSubject();
-        }
-
-        if (!$object) {
-            $object = $this->getNewInstance();
-        }
-
-        $this->setSubject($object);
-
         // add the custom inline validation option
         $metadata = $this->validator->getMetadataFactory()->getClassMetadata($this->class);
         $metadata->addConstraint(new \Sonata\AdminBundle\Validator\Constraints\InlineConstraint(array(
@@ -931,12 +951,11 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
             'method'  => 'validate'
         )));
 
-        $options['data']       = $object;
-        $options['data_class'] = $this->getClass();
+        $this->formOptions['data_class'] = $this->getClass();
 
         $formBuilder = $this->getFormContractor()->getFormBuilder(
             $this->getUniqid(),
-            array_merge($this->formOptions, $options)
+            $this->formOptions
         );
 
         $this->defineFormBuilder($formBuilder);
@@ -952,8 +971,6 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
     {
         $mapper = new FormMapper($this->getFormContractor(), $formBuilder, $this);
 
-        $this->buildFormFieldDescriptions();
-
         $this->configureFormFields($mapper);
     }
 
@@ -985,60 +1002,6 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
         return $this->modelManager->findOne($this->getClass(), $id);
     }
 
-    /**
-     * build the form group array
-     *
-     * @return void
-     */
-    public function buildFormGroups()
-    {
-        if ($this->loaded['form_groups']) {
-            return;
-        }
-
-        $this->loaded['form_groups'] = true;
-
-        if (!$this->formGroups) {
-            $this->formGroups = array(
-                false => array('fields' => array_keys($this->getFormFieldDescriptions()))
-            );
-        }
-
-        // normalize array
-        foreach ($this->formGroups as $name => $group) {
-            if (!isset($this->formGroups[$name]['collapsed'])) {
-                $this->formGroups[$name]['collapsed'] = false;
-            }
-        }
-    }
-
-      /**
-     * build the view group array
-     *
-     * @return void
-     */
-    public function buildViewGroups()
-    {
-        if ($this->loaded['view_groups']) {
-            return;
-        }
-
-        $this->loaded['view_groups'] = true;
-
-        if (!$this->viewGroups) {
-            $this->viewGroups = array(
-                false => array('fields' => array_keys($this->getViewFieldDescriptions()))
-            );
-        }
-
-        // normalize array
-        foreach ($this->viewGroups as $name => $group) {
-            if (!isset($this->viewGroups[$name]['collapsed'])) {
-                $this->viewGroups[$name]['collapsed'] = false;
-            }
-        }
-    }
-
     /**
      * Returns a form depend on the given $object
      *
@@ -1046,24 +1009,11 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
      * @param array $options the form options
      * @return \Symfony\Component\Form\Form
      */
-    public function getForm($object = null, array $options = array())
+    public function getForm()
     {
-        if (!$object) {
-            $object = $this->getNewInstance();
-        }
+        $this->buildForm();
 
-        // append parent object if any
-        // todo : clean the way the Admin class can retrieve set the object
-        if ($this->isChild() && $this->getParentAssociationMapping()) {
-            $parent = $this->getParent()->getObject($this->request->get($this->getParent()->getIdParameter()));
-
-            $propertyPath = new \Symfony\Component\Form\Util\PropertyPath($this->getParentAssociationMapping());
-            $propertyPath->setValue($object, $parent);
-        }
-
-        $formBuilder = $this->getFormBuilder($object, $options);
-
-        return $formBuilder->getForm();
+        return $this->form;
     }
 
     /**
@@ -1072,27 +1022,11 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
      * @param array $options
      * @return \Sonata\AdminBundle\Admin\FieldDescriptionCollection
      */
-    public function getList(array $options = array())
+    public function getList()
     {
-        $list = $this->getListBuilder()->getBaseList($options);
-
-        $mapper = new ListMapper($this->getListBuilder(), $list, $this);
-
-        $this->buildListFieldDescriptions();
+        $this->buildList();
 
-        $this->configureListFields($mapper);
-
-        foreach ($this->getListFieldDescriptions() as $fieldDescription) {
-
-            // do not add field already set in the configureListFields method
-            if ($mapper->has($fieldDescription->getFieldName())) {
-                continue;
-            }
-
-            $mapper->add($fieldDescription);
-        }
-
-        return $list;
+        return $this->list;
     }
 
     /**
@@ -1102,7 +1036,7 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
      */
     public function getDatagrid()
     {
-        $this->buildFilterFieldDescriptions();
+        $this->buildDatagrid();
 
         return $this->datagrid;
     }
@@ -1204,15 +1138,11 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
 
     public function getFormGroups()
     {
-        $this->buildFormGroups();
-
         return $this->formGroups;
     }
 
     public function getViewGroups()
     {
-        $this->buildViewGroups();
-
         return $this->viewGroups;
     }
 
@@ -1287,7 +1217,7 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
      */
     public function getFormFieldDescriptions()
     {
-        $this->buildFormFieldDescriptions();
+        $this->buildForm();
 
         return $this->formFieldDescriptions;
     }
@@ -1311,8 +1241,6 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
      */
     public function hasFormFieldDescription($name)
     {
-        $this->buildFormFieldDescriptions();
-
         return array_key_exists($name, $this->formFieldDescriptions) ? true : false;
     }
 
@@ -1344,11 +1272,9 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
      *
      * @return array collection of form FieldDescription
      */
-    public function getViewFieldDescriptions()
+    public function getShowFieldDescriptions()
     {
-        $this->buildViewFieldDescriptions();
-
-        return $this->viewFieldDescriptions;
+        return $this->showFieldDescriptions;
     }
 
     /**
@@ -1357,9 +1283,9 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
      * @param string $name
      * @return \Sonata\AdminBundle\Admin\FieldDescriptionInterface
      */
-    public function getViewFieldDescription($name)
+    public function getShowFieldDescription($name)
     {
-        return $this->hasViewFieldDescription($name) ? $this->viewFieldDescriptions[$name] : null;
+        return $this->hasShowFieldDescription($name) ? $this->showFieldDescriptions[$name] : null;
     }
 
     /**
@@ -1368,11 +1294,9 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
      * @param string $name
      * @return bool
      */
-    public function hasViewFieldDescription($name)
+    public function hasShowFieldDescription($name)
     {
-        $this->buildViewFieldDescriptions();
-
-        return array_key_exists($name, $this->viewFieldDescriptions);
+        return array_key_exists($name, $this->showFieldDescriptions);
     }
 
     /**
@@ -1382,9 +1306,9 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
      * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
      * @return void
      */
-    public function addViewFieldDescription($name, FieldDescriptionInterface $fieldDescription)
+    public function addShowFieldDescription($name, FieldDescriptionInterface $fieldDescription)
     {
-        $this->viewFieldDescriptions[$name] = $fieldDescription;
+        $this->showFieldDescriptions[$name] = $fieldDescription;
     }
 
     /**
@@ -1393,9 +1317,9 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
      * @param string $name
      * @return void
      */
-    public function removeViewFieldDescription($name)
+    public function removeShowFieldDescription($name)
     {
-        unset($this->viewFieldDescriptions[$name]);
+        unset($this->showFieldDescriptions[$name]);
     }
 
     /**
@@ -1405,7 +1329,7 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
      */
     public function getListFieldDescriptions()
     {
-        $this->buildListFieldDescriptions();
+        $this->buildList();
 
         return $this->listFieldDescriptions;
     }
@@ -1429,7 +1353,7 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
      */
     public function hasListFieldDescription($name)
     {
-        $this->buildListFieldDescriptions();
+        $this->buildList();
 
         return array_key_exists($name, $this->listFieldDescriptions) ? true : false;
     }
@@ -1476,8 +1400,6 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
      */
     public function hasFilterFieldDescription($name)
     {
-        $this->buildFilterFieldDescriptions();
-
         return array_key_exists($name, $this->filterFieldDescriptions) ? true : false;
     }
 
@@ -1510,8 +1432,6 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
      */
     public function getFilterFieldDescriptions()
     {
-        $this->buildFilterFieldDescriptions();
-
         return $this->filterFieldDescriptions;
     }
 
@@ -1903,20 +1823,20 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
     }
 
     /**
-     * @param \Sonata\AdminBundle\Builder\ViewBuilderInterface $viewBuilder
+     * @param \Sonata\AdminBundle\Builder\ShowBuilderInterface $showBuilder
      * @return void
      */
-    public function setViewBuilder(ViewBuilderInterface $viewBuilder)
+    public function setShowBuilder(ShowBuilderInterface $showBuilder)
     {
-        $this->viewBuilder = $viewBuilder;
+        $this->showBuilder = $showBuilder;
     }
 
     /**
-     * @return \Sonata\AdminBundle\Builder\ViewBuilderInterface
+     * @return \Sonata\AdminBundle\Builder\ShowBuilderInterface
      */
-    public function getViewBuilder()
+    public function getShowBuilder()
     {
-        return $this->viewBuilder;
+        return $this->showBuilder;
     }
 
     /**
@@ -2053,4 +1973,11 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
     {
       return $this->validator;
     }
+
+    public function getShow()
+    {
+        $this->buildShow();
+
+        return $this->show;
+    }
 }

+ 1 - 3
Admin/AdminInterface.php

@@ -109,11 +109,9 @@ interface AdminInterface
 
     /**
      *
-     * @param mixed $object
-     * @param array $options
      * @return \Symfony\Component\Form\FormBuilder the form builder
      */
-    function getFormBuilder($object = null, $options = array());
+    function getFormBuilder();
 
     /**
      * @abstract

+ 26 - 1
Admin/FieldDescriptionCollection.php

@@ -12,7 +12,7 @@ namespace Sonata\AdminBundle\Admin;
 
 use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
 
-class FieldDescriptionCollection
+class FieldDescriptionCollection implements \ArrayAccess, \Countable
 {
     protected $elements = array();
 
@@ -66,4 +66,29 @@ class FieldDescriptionCollection
             unset($this->elements[$name]);
         }
     }
+
+    public function offsetExists($offset)
+    {
+        return $this->has($offset);
+    }
+
+    public function offsetGet($offset)
+    {
+        return $this->get($offset);
+    }
+
+    public function offsetSet($offset, $value)
+    {
+        throw new \RunTimeException('Cannot set value, use add');
+    }
+
+    public function offsetUnset($offset)
+    {
+        $this->remove($offset);
+    }
+
+    public function count()
+    {
+        return count($this->elements);
+    }
 }

+ 2 - 2
Builder/ORM/DatagridBuilder.php

@@ -25,7 +25,6 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo;
 
 class DatagridBuilder implements DatagridBuilderInterface
 {
-
     protected $formFactory;
 
     /**
@@ -169,7 +168,7 @@ class DatagridBuilder implements DatagridBuilderInterface
             return false;
         }
 
-        switch($fieldDescription->getType()) {
+        switch($fieldDescription->getMappingType()) {
             case ClassMetadataInfo::MANY_TO_ONE:
                 $options = $fieldDescription->getOption('filter_field_options');
                 $filter = new \Sonata\AdminBundle\Filter\ORM\IntegerFilter($fieldDescription);
@@ -180,6 +179,7 @@ class DatagridBuilder implements DatagridBuilderInterface
                 $options = $fieldDescription->getOption('filter_field_options');
                 $options['choices'] = $this->getChoices($fieldDescription);
 
+
                 $fieldDescription->setOption('filter_field_options', $options);
 
                 $filter = new \Sonata\AdminBundle\Filter\ORM\ChoiceFilter($fieldDescription);

+ 2 - 1
Builder/ORM/FormContractor.php

@@ -46,6 +46,8 @@ class FormContractor implements FormContractorInterface
     {
         $options = array();
 
+        $options['data_class']    = $fieldDescription->getTargetEntity();
+
         if (!$fieldDescription->hasAssociationAdmin()) {
             return $options;
         }
@@ -65,7 +67,6 @@ class FormContractor implements FormContractorInterface
         }
 
         $options['class']         = $fieldDescription->getTargetEntity();
-        $options['data_class']    = $fieldDescription->getTargetEntity();
         $options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();
 
         if ($fieldDescription->getOption('edit') == 'list') {

+ 22 - 8
Builder/ORM/ViewBuilder.php

@@ -15,11 +15,11 @@ use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
 use Sonata\AdminBundle\Model\ModelManagerInterface;
 use Sonata\AdminBundle\Admin\AdminInterface;
 use Sonata\AdminBundle\Admin\FieldDescriptionCollection;
-use Sonata\AdminBundle\Builder\ViewBuilderInterface;
+use Sonata\AdminBundle\Builder\ShowBuilderInterface;
 
 use Doctrine\ORM\Mapping\ClassMetadataInfo;
 
-class ViewBuilder implements ViewBuilderInterface
+class ShowBuilder implements ShowBuilderInterface
 {
     public function getBaseList(array $options = array())
     {
@@ -28,7 +28,21 @@ class ViewBuilder implements ViewBuilderInterface
 
     public function addField(FieldDescriptionCollection $list, FieldDescriptionInterface $fieldDescription)
     {
-        return $list->add($fieldDescription);
+        if (!$fieldDescription->getType()) {
+            return false;
+        }
+
+        switch($fieldDescription->getMappingType()) {
+            case ClassMetadataInfo::MANY_TO_ONE:
+            case ClassMetadataInfo::MANY_TO_MANY:
+            case ClassMetadataInfo::ONE_TO_MANY:
+            case ClassMetadataInfo::ONE_TO_ONE:
+                // todo
+                return;
+            default:
+                $list->add($fieldDescription);
+        }
+
     }
 
     /**
@@ -67,22 +81,22 @@ class ViewBuilder implements ViewBuilderInterface
 
         if (!$fieldDescription->getTemplate()) {
 
-            $fieldDescription->setTemplate(sprintf('SonataAdminBundle:CRUD:view_%s.html.twig', $fieldDescription->getType()));
+            $fieldDescription->setTemplate(sprintf('SonataAdminBundle:CRUD:show_%s.html.twig', $fieldDescription->getType()));
 
             if ($fieldDescription->getType() == ClassMetadataInfo::MANY_TO_ONE) {
-                $fieldDescription->setTemplate('SonataAdminBundle:CRUD:view_orm_many_to_one.html.twig');
+                $fieldDescription->setTemplate('SonataAdminBundle:CRUD:show_orm_many_to_one.html.twig');
             }
 
             if ($fieldDescription->getType() == ClassMetadataInfo::ONE_TO_ONE) {
-                $fieldDescription->setTemplate('SonataAdminBundle:CRUD:view_orm_one_to_one.html.twig');
+                $fieldDescription->setTemplate('SonataAdminBundle:CRUD:show_orm_one_to_one.html.twig');
             }
 
             if ($fieldDescription->getType() == ClassMetadataInfo::ONE_TO_MANY) {
-                $fieldDescription->setTemplate('SonataAdminBundle:CRUD:view_orm_one_to_many.html.twig');
+                $fieldDescription->setTemplate('SonataAdminBundle:CRUD:show_orm_one_to_many.html.twig');
             }
 
             if ($fieldDescription->getType() == ClassMetadataInfo::MANY_TO_MANY) {
-                $fieldDescription->setTemplate('SonataAdminBundle:CRUD:view_orm_many_to_many.html.twig');
+                $fieldDescription->setTemplate('SonataAdminBundle:CRUD:show_orm_many_to_many.html.twig');
             }
         }
 

+ 1 - 1
Builder/ViewBuilderInterface.php

@@ -16,7 +16,7 @@ use Sonata\AdminBundle\Model\ModelManagerInterface;
 use Sonata\AdminBundle\Admin\AdminInterface;
 use Sonata\AdminBundle\Admin\FieldDescriptionCollection;
 
-interface ViewBuilderInterface
+interface ShowBuilderInterface
 {
     /**
      * @abstract

+ 10 - 5
Controller/CRUDController.php

@@ -191,7 +191,8 @@ class CRUDController extends Controller
 
         $this->admin->setSubject($object);
 
-        $form = $this->admin->getForm($object);
+        $form = $this->admin->getForm();
+        $form->setData($object);
 
         if ($this->get('request')->getMethod() == 'POST') {
             $form->bindRequest($this->get('request'));
@@ -345,9 +346,9 @@ class CRUDController extends Controller
      *
      * @return \Symfony\Component\HttpFoundation\Response
      */
-    public function viewAction($id)
+    public function showAction($id)
     {
-        if (false === $this->admin->isGranted('VIEW')) {
+        if (false === $this->admin->isGranted('SHOW')) {
             throw new AccessDeniedException();
         }
 
@@ -359,9 +360,13 @@ class CRUDController extends Controller
 
         $this->admin->setSubject($object);
 
-        return $this->render($this->admin->getViewTemplate(), array(
-            'action'         => 'view',
+        // build the show list
+        $elements = $this->admin->getShow();
+
+        return $this->render($this->admin->getShowTemplate(), array(
+            'action'         => 'show',
             'object'         => $object,
+            'elements'       => $this->admin->getShow(),
             'admin'          => $this->admin,
             'base_template'  => $this->getBaseTemplate(),
         ));

+ 1 - 0
Datagrid/DatagridMapper.php

@@ -48,6 +48,7 @@ class DatagridMapper
             $fieldDescription->mergeOptions($fieldDescriptionOptions);
 
         } else if (is_string($name) && !$this->admin->hasFormFieldDescription($name)) {
+
             $fieldDescription = $this->admin->getModelManager()->getNewFieldDescriptionInstance(
                 $this->admin->getClass(),
                 $name,

+ 2 - 2
DependencyInjection/AddDependencyCallsCompilerPass.php

@@ -100,8 +100,8 @@ class AddDependencyCallsCompilerPass implements CompilerPassInterface
             $definition->addMethodCall('setFormContractor', array(new Reference(sprintf('sonata.admin.builder.%s_form', $manager_type))));
         }
 
-        if (!$definition->hasMethodCall('setViewBuilder')) {
-            $definition->addMethodCall('setViewBuilder', array(new Reference(sprintf('sonata.admin.builder.%s_view', $manager_type))));
+        if (!$definition->hasMethodCall('setShowBuilder')) {
+            $definition->addMethodCall('setShowBuilder', array(new Reference(sprintf('sonata.admin.builder.%s_show', $manager_type))));
         }
 
         if (!$definition->hasMethodCall('setListBuilder')) {

+ 1 - 2
Resources/config/doctrine_orm.xml

@@ -16,12 +16,11 @@
 
         <service id="sonata.admin.builder.orm_list" class="Sonata\AdminBundle\Builder\ORM\ListBuilder" />
 
-        <service id="sonata.admin.builder.orm_view" class="Sonata\AdminBundle\Builder\ORM\ViewBuilder" />
+        <service id="sonata.admin.builder.orm_show" class="Sonata\AdminBundle\Builder\ORM\ShowBuilder" />
 
         <service id="sonata.admin.builder.orm_datagrid" class="Sonata\AdminBundle\Builder\ORM\DatagridBuilder">
             <argument type="service" id="form.factory" />
         </service>
 
     </services>
-
 </container>

+ 2 - 6
Resources/views/CRUD/base_edit.html.twig

@@ -14,8 +14,8 @@ file that was distributed with this source code.
 {% block actions %}
     <div class="sonata-actions">
         <ul>
-            {% if admin.id(object) and admin.isGranted('VIEW') and admin.getViewFieldDescriptions is not empty %}
-                <li class="sonata-action-element"><a href="{{ admin.generateUrl('view', {'id' : admin.id(object)}) }}">{% trans from 'SonataAdminBundle' %}link_action_view{% endtrans %}</a></li>
+            {% if admin.id(object) and admin.isGranted('VIEW') and admin.show|length > 0 %}
+                <li class="sonata-action-element"><a href="{{ admin.generateUrl('show', {'id' : admin.id(object)}) }}">{% trans from 'SonataAdminBundle' %}link_action_show{% endtrans %}</a></li>
             {% endif %}
             {% if admin.isGranted('CREATE')%}
                 <li class="sonata-action-element"><a href="{{ admin.generateUrl('create') }}">{% trans from 'SonataAdminBundle' %}link_action_create{% endtrans %}</a></li>
@@ -58,13 +58,9 @@ file that was distributed with this source code.
                     <div class="sonata-ba-collapsed-fields">
             {% endif %}
 
-
             {% for field_name in form_group.fields %}
                 {% if admin.formfielddescriptions[field_name] is defined %}
-                    {#{{ admin.formfielddescriptions[field_name]|render_form_element(form, object) }}#}
-
                     {{ form_row(form[field_name])}}
-
                 {% endif %}
             {% endfor %}
 

+ 2 - 2
Resources/views/CRUD/base_list_field.html.twig

@@ -10,12 +10,12 @@ file that was distributed with this source code.
 #}
 
 <td class="sonata-ba-list-field sonata-ba-list-field-{{ field_description.type }}" objectId="{{ admin.id(object) }}">
-    {% if field_description.options.identifier is defined and admin.isGranted(['EDIT', 'VIEW']) %}
+    {% if field_description.options.identifier is defined and admin.isGranted(['EDIT', 'SHOW']) %}
 
         {% if admin.isGranted('EDIT') %}
             <a href="{{ admin.generateUrl('edit', {'id': admin.id(object)}) }}">
         {% else %}
-            <a href="{{ admin.generateUrl('view', {'id': admin.id(object)}) }}">
+            <a href="{{ admin.generateUrl('show', {'id': admin.id(object)}) }}">
         {% endif %}
 
             {% block field %}{{ value }}{% endblock %}

+ 3 - 3
Resources/views/CRUD/base_view.html.twig

@@ -27,7 +27,7 @@ file that was distributed with this source code.
 
 {% block side_menu %}{{ admin.sidemenu(action).render|raw }}{% endblock %}
 
-{% block view %}
+{% block show %}
     <div class="sonata-ba-view">
         {% for name, view_group in admin.viewgroups %}
             <table>
@@ -41,8 +41,8 @@ file that was distributed with this source code.
 
                 {% for field_name in view_group.fields %}
                     <tr class="sonata-ba-view-container">
-                        {% if admin.viewfielddescriptions[field_name] is defined %}
-                            {{ admin.viewfielddescriptions[field_name]|render_view_element(object) }}
+                        {% if admin.show[field_name] is defined %}
+                            {{ admin.show[field_name]|render_view_element(object) }}
                         {% endif %}
                     </tr>
                 {% endfor %}

Resources/views/CRUD/base_view_field.html.twig → Resources/views/CRUD/base_show_field.html.twig


+ 1 - 1
Resources/views/CRUD/list.html.twig

@@ -9,4 +9,4 @@ file that was distributed with this source code.
 
 #}
 
-{% extends 'SonataAdminBundle:CRUD:base_list.html.twig' %}
+{% extends 'SonataAdminBundle:CRUD:base_list.html.twig' %}

+ 1 - 1
Resources/views/CRUD/view.html.twig

@@ -9,5 +9,5 @@ file that was distributed with this source code.
 
 #}
 
-{% extends 'SonataAdminBundle:CRUD:base_view.html.twig' %}
+{% extends 'SonataAdminBundle:CRUD:base_show.html.twig' %}
 

+ 1 - 1
Resources/views/CRUD/view_date.html.twig

@@ -9,6 +9,6 @@ file that was distributed with this source code.
 
 #}
 
-{% extends 'SonataAdminBundle:CRUD:base_view_field.html.twig' %}
+{% extends 'SonataAdminBundle:CRUD:base_show_field.html.twig' %}
 
 {% block value %}{{ value|date('F j, Y') }}{% endblock %}

+ 1 - 1
Resources/views/CRUD/view_datetime.html.twig

@@ -9,7 +9,7 @@ file that was distributed with this source code.
 
 #}
 
-{% extends 'SonataAdminBundle:CRUD:base_view_field.html.twig' %}
+{% extends 'SonataAdminBundle:CRUD:base_show_field.html.twig' %}
 
 {% block value %}{{ value|date }}{% endblock %}
 

+ 3 - 3
Resources/views/standard_layout.html.twig

@@ -55,7 +55,7 @@ file that was distributed with this source code.
         {# initialize block value #}
         {% set preview      = block('preview') %}
         {% set form         = block('form') %}
-        {% set view         = block('view') %}
+        {% set show         = block('show') %}
         {% set list_table   = block('list_table') %}
         {% set list_filters = block('list_filters') %}
         {% set side_menu    = block('side_menu') %}
@@ -126,8 +126,8 @@ file that was distributed with this source code.
                         <div class="sonata-ba-content">{{ content|raw }}</div>
                     {% endif %}
 
-                    {% if view is not empty %}
-                        <div class="sonata-ba-view">{{ view|raw }}</div>
+                    {% if show is not empty %}
+                        <div class="sonata-ba-show">{{ show|raw }}</div>
                     {% endif %}
 
                     {% if form is not empty %}

+ 2 - 2
Security/Acl/Permission/AdminPermissionMap.php

@@ -22,7 +22,7 @@ use Symfony\Component\Security\Acl\Permission\PermissionMapInterface;
  */
 class AdminPermissionMap implements PermissionMapInterface
 {
-    const PERMISSION_VIEW        = 'VIEW';
+    const PERMISSION_SHOW        = 'SHOW';
     const PERMISSION_EDIT        = 'EDIT';
     const PERMISSION_CREATE      = 'CREATE';
     const PERMISSION_DELETE      = 'DELETE';
@@ -38,7 +38,7 @@ class AdminPermissionMap implements PermissionMapInterface
             MaskBuilder::MASK_LIST
         ),
 
-        self::PERMISSION_VIEW => array(
+        self::PERMISSION_SHOW => array(
             MaskBuilder::MASK_VIEW,
         ),
 

+ 3 - 3
Show/ShowMapper.php

@@ -8,7 +8,7 @@
  * file that was distributed with this source code.
  *
  */
-namespace Sonata\AdminBundle\Datagrid;
+namespace Sonata\AdminBundle\Show;
 
 use Sonata\AdminBundle\Admin\AdminInterface;
 use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
@@ -48,7 +48,7 @@ class ShowMapper
             $fieldDescription = $name;
             $fieldDescription->mergeOptions($fieldDescriptionOptions);
 
-        } else if (is_string($name) && !$this->admin->hasListFieldDescription($name)) {
+        } else if (is_string($name) && !$this->admin->hasShowFieldDescription($name)) {
 
             $fieldDescription = $this->admin->getModelManager()->getNewFieldDescriptionInstance(
                 $this->admin->getClass(),
@@ -57,7 +57,7 @@ class ShowMapper
             );
 
             $this->showBuilder->fixFieldDescription($this->admin, $fieldDescription, $fieldDescriptionOptions);
-            $this->admin->addListFieldDescription($name, $fieldDescription);
+            $this->admin->addShowFieldDescription($name, $fieldDescription);
 
         } else if (is_string($name) && $this->admin->hasShowFieldDescription($name)) {
             $fieldDescription = $this->admin->getShowFieldDescription($name);

+ 1 - 57
Twig/Extension/SonataAdminExtension.php

@@ -41,7 +41,6 @@ class SonataAdminExtension extends \Twig_Extension
     {
         return array(
             'render_list_element'     => new \Twig_Filter_Method($this, 'renderListElement', array('is_safe' => array('html'))),
-//            'render_form_element'     => new \Twig_Filter_Method($this, 'renderFormElement', array('is_safe' => array('html'))),
             'render_filter_element'   => new \Twig_Filter_Method($this, 'renderFilterElement', array('is_safe' => array('html'))),
             'render_view_element'     => new \Twig_Filter_Method($this, 'renderViewElement', array('is_safe' => array('html'))),
             'render_relation_element' => new \Twig_Filter_Method($this, 'renderRelationElement', array('is_safe' => array('html'))),
@@ -177,7 +176,7 @@ class SonataAdminExtension extends \Twig_Extension
      */
     public function renderViewElement(FieldDescriptionInterface $fieldDescription, $object)
     {
-        $template = $this->getTemplate($fieldDescription, 'SonataAdminBundle:CRUD:base_view_field.html.twig');
+        $template = $this->getTemplate($fieldDescription, 'SonataAdminBundle:CRUD:base_show_field.html.twig');
 
         try {
             $value = $fieldDescription->getValue($object);
@@ -192,61 +191,6 @@ class SonataAdminExtension extends \Twig_Extension
         ));
     }
 
-//    /**
-//     * render a field element from the FieldDescription
-//     *
-//     * @throws InvalidArgumentException
-//     * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
-//     * @param \Sumfony\Component\Form\FormView $formView
-//     * @param mixed $object
-//     * @param array $params
-//     * @return string
-//     */
-//    public function renderFormElement(FieldDescriptionInterface $fieldDescription, FormView $formView, $object, $params = array())
-//    {
-//        if (!$fieldDescription->getFieldName()) {
-//            return '';
-//        }
-//
-//        if (!$formView->offsetExists($fieldDescription->getFieldName())) {
-//            return;
-//        }
-//
-//        $children = $formView->offsetGet($fieldDescription->getFieldName());
-//
-//        if (in_array('hidden', $children->get('types'))) {
-//            return '';
-//        }
-//
-//        // find the correct edit parameter
-//        //  edit   : standard | inline
-//        //  inline : natural | table
-//        $parentFieldDescription = $fieldDescription->getAdmin()->getParentFieldDescription();
-//
-//        if (!$parentFieldDescription) {
-//            $params['edit']          = $fieldDescription->getOption('edit', 'standard');
-//            $params['inline']        = $fieldDescription->getOption('inline', 'natural');
-//
-//            $base_template = sprintf('SonataAdminBundle:CRUD:base_%s_edit_field.html.twig', 'standard');
-//        } else {
-//            $params['edit']          = $parentFieldDescription->getOption('edit', 'standard');
-//            $params['inline']        = $parentFieldDescription->getOption('inline', 'natural');
-//
-//            $base_template = sprintf('SonataAdminBundle:CRUD:base_%s_edit_field.html.twig', $params['edit']);
-//        }
-//
-//        $template = $this->getTemplate($fieldDescription, 'SonataAdminBundle:CRUD:base_standard_edit_field.html.twig');
-//
-//        return $this->output($fieldDescription, $template, array_merge($params, array(
-//            'admin'             => $fieldDescription->getAdmin(),
-//            'object'            => $object,
-//            'field_description' => $fieldDescription,
-//            'value'             => $this->getValueFromFieldDescription($object, $fieldDescription, $params),
-//            'field_element'     => $children,
-//            'base_template'     => $fieldDescription->getOption('base_template', $base_template)
-//        )));
-//    }
-
     /**
      * @throws \RunTimeException
      * @param $element