浏览代码

Refactor template methods, add delete template key

Thomas Rabaix 13 年之前
父节点
当前提交
cd7c39eb6d
共有 5 个文件被更改,包括 29 次插入51 次删除
  1. 0 30
      Admin/Admin.php
  2. 5 0
      CHANGELOG.md
  3. 21 21
      Controller/CRUDController.php
  4. 1 0
      DependencyInjection/Configuration.php
  5. 2 0
      Resources/doc/reference/templates.rst

+ 0 - 30
Admin/Admin.php

@@ -1082,36 +1082,6 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
         return $this->routeGenerator->generateUrl($this, $name, $parameters, $absolute);
     }
 
-    /**
-     * Returns the list template
-     *
-     * @return string the list template
-     */
-    public function getListTemplate()
-    {
-        return $this->getTemplate('list');
-    }
-
-    /**
-     * Returns the edit template
-     *
-     * @return string the edit template
-     */
-    public function getEditTemplate()
-    {
-        return $this->getTemplate('edit');
-    }
-
-    /**
-     * Returns the view template
-     *
-     * @return string the view template
-     */
-    public function getShowTemplate()
-    {
-        return $this->getTemplate('show');
-    }
-
     /**
      * @param array $templates
      *

+ 5 - 0
CHANGELOG.md

@@ -1,6 +1,11 @@
 CHANGELOG
 =========
 
+### 2012-08-05
+
+* [BC BREAK] remove ``getListTemplate``, ``getEditTemplate``, ``getShowTemplate`` => just use ``getTemplate('edit')``
+* add a ``delete`` template configuration entry
+
 ### 2012-06-05
 
 * [BC BREAK] Fix bug introduces by 09334d81, now an admin must have the role ``ROLE_SONATA_ADMIN`` to see the top bar navigation

+ 21 - 21
Controller/CRUDController.php

@@ -156,7 +156,7 @@ class CRUDController extends Controller
         // set the theme for the current Admin Form
         $this->get('twig')->getExtension('form')->renderer->setTheme($formView, $this->admin->getFilterTheme());
 
-        return $this->render($this->admin->getListTemplate(), array(
+        return $this->render($this->admin->getTemplate('edit'), array(
             'action'   => 'list',
             'form'     => $formView,
             'datagrid' => $datagrid
@@ -220,7 +220,7 @@ class CRUDController extends Controller
             return new RedirectResponse($this->admin->generateUrl('list'));
         }
 
-        return $this->render('SonataAdminBundle:CRUD:delete.html.twig', array(
+        return $this->render($this->admin->getTemplate('delete'), array(
             'object' => $object,
             'action' => 'delete'
         ));
@@ -239,7 +239,7 @@ class CRUDController extends Controller
     {
         // the key used to lookup the template
         $templateKey = 'edit';
-        
+
         $id = $this->get('request')->get($this->admin->getIdParameter());
 
         $object = $this->admin->getObject($id);
@@ -259,9 +259,9 @@ class CRUDController extends Controller
 
         if ($this->get('request')->getMethod() == 'POST') {
             $form->bindRequest($this->get('request'));
-            
-            $isFormValid = $form->isValid(); 
-            
+
+            $isFormValid = $form->isValid();
+
              // persist if the form was valid and if in preview mode the preview was approved
             if ($isFormValid && (!$this->isInPreviewMode() || $this->isPreviewApproved())) {
                 $this->admin->update($object);
@@ -277,7 +277,7 @@ class CRUDController extends Controller
                 // redirect to edit mode
                 return $this->redirectTo($object);
             }
-            
+
             // show an error message if the form failed validation
             if (!$isFormValid) {
                 $this->get('session')->setFlash('sonata_flash_error', 'flash_edit_error');
@@ -427,7 +427,7 @@ class CRUDController extends Controller
     {
         // the key used to lookup the template
         $templateKey = 'edit';
-        
+
         if (false === $this->admin->isGranted('CREATE')) {
             throw new AccessDeniedException();
         }
@@ -441,9 +441,9 @@ class CRUDController extends Controller
 
         if ($this->get('request')->getMethod() == 'POST') {
             $form->bindRequest($this->get('request'));
-            
-            $isFormValid = $form->isValid(); 
-            
+
+            $isFormValid = $form->isValid();
+
             // persist if the form was valid and if in preview mode the preview was approved
             if ($isFormValid && (!$this->isInPreviewMode() || $this->isPreviewApproved())) {
                 $this->admin->create($object);
@@ -459,7 +459,7 @@ class CRUDController extends Controller
                 // redirect to edit mode
                 return $this->redirectTo($object);
             }
-            
+
             // show an error message if the form failed validation
             if (!$isFormValid) {
                 $this->get('session')->setFlash('sonata_flash_error', 'flash_create_error');
@@ -480,10 +480,10 @@ class CRUDController extends Controller
             'object' => $object,
         ));
     }
-    
+
     /**
      * Returns true if the preview is requested to be shown
-     * 
+     *
      * @return boolean
      */
     protected function isPreviewRequested()
@@ -493,20 +493,20 @@ class CRUDController extends Controller
 
     /**
      * Returns true if the preview has been approved
-     * 
+     *
      * @return boolean
      */
     protected function isPreviewApproved()
     {
         return ($this->get('request')->get('btn_preview_approve') !== null);
     }
-    
+
     /**
      * Returns true if the request is in the preview workflow
-     * 
+     *
      * That means either a preview is requested or the preview has already been shown
      * and it got approved/declined.
-     * 
+     *
      * @return boolean
      */
     protected function isInPreviewMode()
@@ -519,7 +519,7 @@ class CRUDController extends Controller
 
     /**
      * Returns true if the preview has been declined
-     * 
+     *
      * @return boolean
      */
     protected function isPreviewDeclined()
@@ -548,7 +548,7 @@ class CRUDController extends Controller
 
         $this->admin->setSubject($object);
 
-        return $this->render($this->admin->getShowTemplate(), array(
+        return $this->render($this->admin->getTemplate('show'), array(
             'action'   => 'show',
             'object'   => $object,
             'elements' => $this->admin->getShow(),
@@ -630,7 +630,7 @@ class CRUDController extends Controller
 
         $this->admin->setSubject($object);
 
-        return $this->render($this->admin->getShowTemplate(), array(
+        return $this->render($this->admin->getTemplate('show'), array(
             'action'   => 'show',
             'object'   => $object,
             'elements' => $this->admin->getShow(),

+ 1 - 0
DependencyInjection/Configuration.php

@@ -138,6 +138,7 @@ class Configuration implements ConfigurationInterface
                         ->scalarNode('action')->defaultValue('SonataAdminBundle:CRUD:action.html.twig')->cannotBeEmpty()->end()
                         ->scalarNode('list_block')->defaultValue('SonataAdminBundle:Block:block_admin_list.html.twig')->cannotBeEmpty()->end()
                         ->scalarNode('short_object_description')->defaultValue('SonataAdminBundle:Helper:short-object-description.html.twig')->cannotBeEmpty()->end()
+                        ->scalarNode('delete')->defaultValue('SonataAdminBundle:CRUD:delete.html.twig')->cannotBeEmpty()->end()
                     ->end()
                 ->end()
             ->end()

+ 2 - 0
Resources/doc/reference/templates.rst

@@ -17,6 +17,7 @@ By default, an Admin class uses a set of templates, it is possible to tweak the
             edit:    SonataAdminBundle:CRUD:edit.html.twig
             history: SonataAdminBundle:CRUD:history.html.twig
             preview: SonataAdminBundle:CRUD:preview.html.twig
+            delete:  SonataAdminBundle:CRUD:delete.html.twig
 
             # default values of helper templates
             short_object_description: SonataAdminBundle:Helper:short-object-description.html.twig
@@ -37,6 +38,7 @@ Usage of each template :
 * list_block : the template used for the list of admin blocks on the dashboard
 * preview : the template to use for previewing an edit / create action
 * short_object_description: used to represent the entity in one-to-one/many-to-one relations
+* delete: the template to use for the delete action
 
 The default values will be set only if the ``Admin::setTemplates`` is not called by the Container.