Permalink
Browse files

added second admin class for inline slideshow editing (MinimalSlidesh…

…owAdmin)
  • Loading branch information...
elHornair committed Mar 1, 2013
1 parent 0600ff1 commit 0ebf3dbe752db115b4d0e052e6fe2b615e322be6
Showing with 83 additions and 49 deletions.
  1. +66 −0 Admin/MinimalSlideshowAdmin.php
  2. +5 −46 Admin/SlideshowAdmin.php
  3. +12 −3 Resources/config/admin.xml
@@ -0,0 +1,66 @@
+<?php
+
+namespace Symfony\Cmf\Bundle\BlockBundle\Admin;
+
+use Symfony\Component\Form\FormEvent;
+use Symfony\Component\Form\FormEvents;
+use Doctrine\ODM\PHPCR\ChildrenCollection;
+use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin;
+use Sonata\AdminBundle\Form\FormMapper;
+use Sonata\AdminBundle\Datagrid\ListMapper;
+
+class MinimalSlideshowAdmin extends Admin
+{
+
+ protected $baseRouteName = 'symfony_cmf_block.minimal_slideshow_admin';
+ protected $baseRoutePattern = 'symfony_cmf/block/minimalSlideshow';
+
+ protected function configureListFields(ListMapper $listMapper)
+ {
+ parent::configureListFields($listMapper);
+ $listMapper
+ ->addIdentifier('id', 'text')
+ ->add('title', 'text');
+ }
+
+ protected function configureFormFields(FormMapper $formMapper)
+ {
+ parent::configureFormFields($formMapper);
+ $formMapper
+ ->with('form.group_general')
+ ->add('title', 'text')
+ ->with('Items')
+ ->add('children', 'sonata_type_collection',
+ array(
+ 'by_reference' => false,
+ ),
+ array(
+ 'edit' => 'inline',
+ 'inline' => 'table',
+ 'admin_code' => 'symfony_cmf_block.slideshow_item_admin',
+ 'sortable' => 'position',
+ ))
+ ->end();
+
+ $formBuilder = $formMapper->getFormBuilder();
+ $formBuilder->addEventListener(FormEvents::POST_BIND, array($this, 'onPostBind'));
+
+ }
+
+ // reorder children according to the form data
+ public function onPostBind(FormEvent $event)
+ {
+ /** @var $newCollection ChildrenCollection */
+ $newCollection = $event->getData()->getChildren();
+ $newCollection->clear();
+
+ foreach ($event->getForm()->get('children') as $child) {
+ $newCollection->add($child->getData());
+ }
+ }
+
+ // TODO: Deletion doesn't work yet -> do we need to manually delete?
+ // TODO: Add doesn't work yet -> problem related to http://www.doctrine-project.org/jira/browse/PHPCR-98 ?
+ // TODO: or do we just have to add the name to the item/image?
+
+}
View
@@ -2,61 +2,20 @@
namespace Symfony\Cmf\Bundle\BlockBundle\Admin;
-use Symfony\Component\Form\FormEvent;
-use Symfony\Component\Form\FormEvents;
-use Doctrine\ODM\PHPCR\ChildrenCollection;
-use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin;
use Sonata\AdminBundle\Form\FormMapper;
-use Sonata\AdminBundle\Datagrid\ListMapper;
-class SlideshowAdmin extends Admin
+class SlideshowAdmin extends MinimalSlideshowAdmin
{
-
- protected function configureListFields(ListMapper $listMapper)
- {
- parent::configureListFields($listMapper);
- $listMapper
- ->addIdentifier('id', 'text')
- ->add('title', 'text');
- }
+ protected $baseRouteName = 'symfony_cmf_block.slideshow_admin';
+ protected $baseRoutePattern = 'symfony_cmf/block/slideshow';
protected function configureFormFields(FormMapper $formMapper)
{
parent::configureFormFields($formMapper);
$formMapper
->with('form.group_general')
- ->add('title', 'text')
- ->with('Items')
- ->add('children', 'sonata_type_collection',
- array(
- 'by_reference' => false,
- ),
- array(
- 'edit' => 'inline',
- 'inline' => 'table',
- 'admin_code' => 'symfony_cmf_block.slideshow_item_admin',
- 'sortable' => 'position',
- ))
+ ->add('parentDocument', 'doctrine_phpcr_odm_tree', array('root_node' => '/cms/content/blocks_general', 'choice_list' => array(), 'select_root_node' => true))
+ ->add('name', 'text')
->end();
-
- $formBuilder = $formMapper->getFormBuilder();
- $formBuilder->addEventListener(FormEvents::POST_BIND, array($this, 'onPostBind'));
-
}
-
- // reorder children according to the form data
- public function onPostBind(FormEvent $event)
- {
- /** @var $newCollection ChildrenCollection */
- $newCollection = $event->getData()->getChildren();
- $newCollection->clear();
-
- foreach ($event->getForm()->get('children') as $child) {
- $newCollection->add($child->getData());
- }
- }
-
- // TODO: Deletion doesn't work yet -> do we need to manually delete?
- // TODO: Add doesn't work yet -> problem related to http://www.doctrine-project.org/jira/browse/PHPCR-98 ?
-
}
View
@@ -8,6 +8,7 @@
<parameter key="symfony_cmf_block.simple_admin_class">Symfony\Cmf\Bundle\BlockBundle\Admin\SimpleBlockAdmin</parameter>
<parameter key="symfony_cmf_block.simple_document_class">Symfony\Cmf\Bundle\BlockBundle\Document\SimpleBlock</parameter>
<parameter key="symfony_cmf_block.slideshow_admin_class">Symfony\Cmf\Bundle\BlockBundle\Admin\SlideshowAdmin</parameter>
+ <parameter key="symfony_cmf_block.minimal_slideshow_admin_class">Symfony\Cmf\Bundle\BlockBundle\Admin\MinimalSlideshowAdmin</parameter>
<parameter key="symfony_cmf_block.slideshow_document_class">Symfony\Cmf\Bundle\BlockBundle\Document\SlideshowBlock</parameter>
<parameter key="symfony_cmf_block.slideshow_item_admin_class">Symfony\Cmf\Bundle\BlockBundle\Admin\SlideshowItemAdmin</parameter>
<parameter key="symfony_cmf_block.slideshow_item_document_class">Symfony\Cmf\Bundle\BlockBundle\Document\SlideshowItemBlock</parameter>
@@ -29,6 +30,17 @@
</call>
</service>
+ <service id="symfony_cmf_block.minimal_slideshow_admin" class="%symfony_cmf_block.minimal_slideshow_admin_class%">
+ <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" />
+ <argument/>
+ <argument>%symfony_cmf_block.slideshow_document_class%</argument>
+ <argument>SonataAdminBundle:CRUD</argument>
+
+ <call method="setRouteBuilder">
+ <argument type="service" id="sonata.admin.route.path_info_slashes" />
+ </call>
+ </service>
+
<service id="symfony_cmf_block.slideshow_admin" class="%symfony_cmf_block.slideshow_admin_class%">
<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" />
<argument/>
@@ -39,9 +51,6 @@
<argument type="service" id="sonata.admin.route.path_info_slashes" />
</call>
- <call method="setRoot">
- <argument>%symfony_cmf_block.content_basepath%</argument>
- </call>
</service>
<service id="symfony_cmf_block.slideshow_item_admin" class="%symfony_cmf_block.slideshow_item_admin_class%">

0 comments on commit 0ebf3db

Please sign in to comment.