Skip to content
This repository
Browse code

added second admin class for inline slideshow editing (MinimalSlidesh…

…owAdmin)
  • Loading branch information...
commit 0ebf3dbe752db115b4d0e052e6fe2b615e322be6 1 parent 0600ff1
elHornair authored March 01, 2013
66  Admin/MinimalSlideshowAdmin.php
... ...
@@ -0,0 +1,66 @@
  1
+<?php
  2
+
  3
+namespace Symfony\Cmf\Bundle\BlockBundle\Admin;
  4
+
  5
+use Symfony\Component\Form\FormEvent;
  6
+use Symfony\Component\Form\FormEvents;
  7
+use Doctrine\ODM\PHPCR\ChildrenCollection;
  8
+use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin;
  9
+use Sonata\AdminBundle\Form\FormMapper;
  10
+use Sonata\AdminBundle\Datagrid\ListMapper;
  11
+
  12
+class MinimalSlideshowAdmin extends Admin
  13
+{
  14
+
  15
+    protected $baseRouteName = 'symfony_cmf_block.minimal_slideshow_admin';
  16
+    protected $baseRoutePattern = 'symfony_cmf/block/minimalSlideshow';
  17
+
  18
+    protected function configureListFields(ListMapper $listMapper)
  19
+    {
  20
+        parent::configureListFields($listMapper);
  21
+        $listMapper
  22
+            ->addIdentifier('id', 'text')
  23
+            ->add('title', 'text');
  24
+    }
  25
+
  26
+    protected function configureFormFields(FormMapper $formMapper)
  27
+    {
  28
+        parent::configureFormFields($formMapper);
  29
+        $formMapper
  30
+            ->with('form.group_general')
  31
+                ->add('title', 'text')
  32
+            ->with('Items')
  33
+                ->add('children', 'sonata_type_collection',
  34
+                    array(
  35
+                        'by_reference' => false,
  36
+                    ),
  37
+                    array(
  38
+                        'edit' => 'inline',
  39
+                        'inline' => 'table',
  40
+                        'admin_code' => 'symfony_cmf_block.slideshow_item_admin',
  41
+                        'sortable'  => 'position',
  42
+                    ))
  43
+            ->end();
  44
+
  45
+        $formBuilder = $formMapper->getFormBuilder();
  46
+        $formBuilder->addEventListener(FormEvents::POST_BIND, array($this, 'onPostBind'));
  47
+
  48
+    }
  49
+
  50
+    // reorder children according to the form data
  51
+    public function onPostBind(FormEvent $event)
  52
+    {
  53
+        /** @var $newCollection ChildrenCollection */
  54
+        $newCollection = $event->getData()->getChildren();
  55
+        $newCollection->clear();
  56
+
  57
+        foreach ($event->getForm()->get('children') as $child) {
  58
+            $newCollection->add($child->getData());
  59
+        }
  60
+    }
  61
+
  62
+    // TODO: Deletion doesn't work yet -> do we need to manually delete?
  63
+    // TODO: Add doesn't work yet -> problem related to http://www.doctrine-project.org/jira/browse/PHPCR-98 ?
  64
+    // TODO: or do we just have to add the name to the item/image?
  65
+
  66
+}
51  Admin/SlideshowAdmin.php
@@ -2,61 +2,20 @@
2 2
 
3 3
 namespace Symfony\Cmf\Bundle\BlockBundle\Admin;
4 4
 
5  
-use Symfony\Component\Form\FormEvent;
6  
-use Symfony\Component\Form\FormEvents;
7  
-use Doctrine\ODM\PHPCR\ChildrenCollection;
8  
-use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin;
9 5
 use Sonata\AdminBundle\Form\FormMapper;
10  
-use Sonata\AdminBundle\Datagrid\ListMapper;
11 6
 
12  
-class SlideshowAdmin extends Admin
  7
+class SlideshowAdmin extends MinimalSlideshowAdmin
13 8
 {
14  
-
15  
-    protected function configureListFields(ListMapper $listMapper)
16  
-    {
17  
-        parent::configureListFields($listMapper);
18  
-        $listMapper
19  
-            ->addIdentifier('id', 'text')
20  
-            ->add('title', 'text');
21  
-    }
  9
+    protected $baseRouteName = 'symfony_cmf_block.slideshow_admin';
  10
+    protected $baseRoutePattern = 'symfony_cmf/block/slideshow';
22 11
 
23 12
     protected function configureFormFields(FormMapper $formMapper)
24 13
     {
25 14
         parent::configureFormFields($formMapper);
26 15
         $formMapper
27 16
             ->with('form.group_general')
28  
-                ->add('title', 'text')
29  
-            ->with('Items')
30  
-                ->add('children', 'sonata_type_collection',
31  
-                    array(
32  
-                        'by_reference' => false,
33  
-                    ),
34  
-                    array(
35  
-                        'edit' => 'inline',
36  
-                        'inline' => 'table',
37  
-                        'admin_code' => 'symfony_cmf_block.slideshow_item_admin',
38  
-                        'sortable'  => 'position',
39  
-                    ))
  17
+                ->add('parentDocument', 'doctrine_phpcr_odm_tree', array('root_node' => '/cms/content/blocks_general', 'choice_list' => array(), 'select_root_node' => true))
  18
+                ->add('name', 'text')
40 19
             ->end();
41  
-
42  
-        $formBuilder = $formMapper->getFormBuilder();
43  
-        $formBuilder->addEventListener(FormEvents::POST_BIND, array($this, 'onPostBind'));
44  
-
45 20
     }
46  
-
47  
-    // reorder children according to the form data
48  
-    public function onPostBind(FormEvent $event)
49  
-    {
50  
-        /** @var $newCollection ChildrenCollection */
51  
-        $newCollection = $event->getData()->getChildren();
52  
-        $newCollection->clear();
53  
-
54  
-        foreach ($event->getForm()->get('children') as $child) {
55  
-            $newCollection->add($child->getData());
56  
-        }
57  
-    }
58  
-
59  
-    // TODO: Deletion doesn't work yet -> do we need to manually delete?
60  
-    // TODO: Add doesn't work yet -> problem related to http://www.doctrine-project.org/jira/browse/PHPCR-98 ?
61  
-
62 21
 }
15  Resources/config/admin.xml
@@ -8,6 +8,7 @@
8 8
         <parameter key="symfony_cmf_block.simple_admin_class">Symfony\Cmf\Bundle\BlockBundle\Admin\SimpleBlockAdmin</parameter>
9 9
         <parameter key="symfony_cmf_block.simple_document_class">Symfony\Cmf\Bundle\BlockBundle\Document\SimpleBlock</parameter>
10 10
         <parameter key="symfony_cmf_block.slideshow_admin_class">Symfony\Cmf\Bundle\BlockBundle\Admin\SlideshowAdmin</parameter>
  11
+        <parameter key="symfony_cmf_block.minimal_slideshow_admin_class">Symfony\Cmf\Bundle\BlockBundle\Admin\MinimalSlideshowAdmin</parameter>
11 12
         <parameter key="symfony_cmf_block.slideshow_document_class">Symfony\Cmf\Bundle\BlockBundle\Document\SlideshowBlock</parameter>
12 13
         <parameter key="symfony_cmf_block.slideshow_item_admin_class">Symfony\Cmf\Bundle\BlockBundle\Admin\SlideshowItemAdmin</parameter>
13 14
         <parameter key="symfony_cmf_block.slideshow_item_document_class">Symfony\Cmf\Bundle\BlockBundle\Document\SlideshowItemBlock</parameter>
@@ -29,6 +30,17 @@
29 30
             </call>
30 31
         </service>
31 32
 
  33
+        <service id="symfony_cmf_block.minimal_slideshow_admin" class="%symfony_cmf_block.minimal_slideshow_admin_class%">
  34
+            <tag name="sonata.admin" manager_type="doctrine_phpcr" group="dashboard.group_routing" label_catalogue="SymfonyCmfBlockBundle" label="dashboard.minimal_slideshow_block" label_translator_strategy="sonata.admin.label.strategy.underscore" />
  35
+            <argument/>
  36
+            <argument>%symfony_cmf_block.slideshow_document_class%</argument>
  37
+            <argument>SonataAdminBundle:CRUD</argument>
  38
+
  39
+            <call method="setRouteBuilder">
  40
+                <argument type="service" id="sonata.admin.route.path_info_slashes" />
  41
+            </call>
  42
+        </service>
  43
+
32 44
         <service id="symfony_cmf_block.slideshow_admin" class="%symfony_cmf_block.slideshow_admin_class%">
33 45
             <tag name="sonata.admin" manager_type="doctrine_phpcr" group="dashboard.group_content" label_catalogue="SymfonyCmfBlockBundle" label="dashboard.label_slideshow_block" label_translator_strategy="sonata.admin.label.strategy.underscore" />
34 46
             <argument/>
@@ -39,9 +51,6 @@
39 51
                 <argument type="service" id="sonata.admin.route.path_info_slashes" />
40 52
             </call>
41 53
 
42  
-            <call method="setRoot">
43  
-                <argument>%symfony_cmf_block.content_basepath%</argument>
44  
-            </call>
45 54
         </service>
46 55
 
47 56
         <service id="symfony_cmf_block.slideshow_item_admin" class="%symfony_cmf_block.slideshow_item_admin_class%">

0 notes on commit 0ebf3db

Please sign in to comment.
Something went wrong with that request. Please try again.