Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added reordering

  • Loading branch information...
commit e77bbf4583a36557afd782e727365d4a753de799 1 parent a6c9f56
@elHornair elHornair authored
View
24 Admin/SlideshowAdmin.php
@@ -2,6 +2,9 @@
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;
@@ -26,14 +29,31 @@ protected function configureFormFields(FormMapper $formMapper)
->with('Items')
->add('children', 'sonata_type_collection',
array(
- 'by_reference' => false
+ 'by_reference' => false,
),
array(
'edit' => 'inline',
'inline' => 'table',
- 'admin_code' => 'symfony_cmf_block.slideshow_item_admin'
+ '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
View
1  Admin/SlideshowItemAdmin.php
@@ -14,6 +14,7 @@ protected function configureFormFields(FormMapper $formMapper)
$formMapper
->with('form.group_general')
->add('label', 'text')
+ ->add('position', 'hidden', array('mapped' => false))
->end();
}
View
1  Document/SlideshowItemBlock.php
@@ -26,7 +26,6 @@ class SlideshowItemBlock extends BaseBlock
/** @PHPCRODM\Node */
protected $node;
-
/**
* {@inheritdoc}
*/
Please sign in to comment.
Something went wrong with that request. Please try again.