SlideshowBlock #32
Changes from 19 commits
228becd
c792236
34ec2c1
15103ad
a6c9f56
e77bbf4
05e9870
24f298f
e3a8562
0a31b0a
7a38394
dbbdbde
b6a46c1
3fc4a54
2c9ed21
f8e2d13
04ee009
0600ff1
0ebf3db
76fddb6
4147e76
4f56451
57bda6e
be0c58d
84e2de9
37ab49e
0b2ecc3
97f58ef
f728d66
ccc23c3
ec8bc07
bc85342
6aeacfb
ad4a92d
e98ffe5
305b2c6
476631a
183bc29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should try this again once doctrine/phpcr-odm#262 is really fixed |
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Symfony\Cmf\Bundle\BlockBundle\Admin; | ||
|
||
use Sonata\AdminBundle\Form\FormMapper; | ||
|
||
class SlideshowAdmin extends MinimalSlideshowAdmin | ||
{ | ||
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('parentDocument', 'doctrine_phpcr_odm_tree', array('root_node' => '/cms/content/blocks_general', 'choice_list' => array(), 'select_root_node' => true)) | ||
->add('name', 'text') | ||
->end(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Symfony\Cmf\Bundle\BlockBundle\Admin; | ||
|
||
use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin; | ||
use Sonata\AdminBundle\Form\FormMapper; | ||
|
||
class SlideshowItemAdmin extends Admin | ||
{ | ||
protected function configureFormFields(FormMapper $formMapper) | ||
{ | ||
parent::configureFormFields($formMapper); | ||
|
||
// image is only required when creating a new item | ||
// TODO: sonata is not using one admin instance per object, so this doesnt really work - fix it | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here is still a TODO There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably we would need to hook a form transformer. or maybe we can build this into phpcr_odm_image form type to have a sort of 'required' = 'auto' option that checks if the image is new or not. as its the most useful default behaviour, this could actually make a lot of sense. |
||
$imageRequired = ($this->getSubject() && $this->getSubject()->getParent()) ? false : true; | ||
|
||
$formMapper | ||
->with('form.group_general') | ||
->add('label', 'text') | ||
->add('image', 'phpcr_odm_image', array('required' => $imageRequired, 'label' => 'Slide Image', 'data_class' => 'Doctrine\ODM\PHPCR\Document\Image')) | ||
->add('position', 'hidden', array('mapped' => false)) | ||
->end(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,13 +8,16 @@ | |
use Sonata\BlockBundle\Model\BlockInterface; | ||
|
||
/** | ||
* Block that contains other blocks ... | ||
* Block that contains other blocks | ||
* | ||
* @PHPCRODM\Document(referenceable=true) | ||
*/ | ||
class ContainerBlock extends BaseBlock | ||
{ | ||
/** @PHPCRODM\Children */ | ||
/** | ||
* \Doctrine\Common\Collections\ArrayCollection | ||
* @PHPCRODM\Children | ||
*/ | ||
protected $children; | ||
|
||
public function __construct($name = null) | ||
|
@@ -45,15 +48,27 @@ public function setChildren(ChildrenCollection $children) | |
* Add a child to this container | ||
* | ||
* @param BlockInterface $child | ||
* @param string $key OPTIONAL | ||
* @return boolean | ||
*/ | ||
public function addChild(BlockInterface $child, $key = null) | ||
public function addChild(BlockInterface $child) | ||
{ | ||
if ($key != null) { | ||
return $this->children->set($key, $child); | ||
} | ||
|
||
return $this->children->add($child); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why drop this feature of specifying the key? phpcr-odm might likely support the array key for the node name if not otherwise specified. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i re-added this. |
||
|
||
public function addChildren(BlockInterface $children) | ||
{ | ||
return $this->addChild($children); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. huh? should $children not be a list of children here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah no sorry, the issue is the form layer guessing and not knowing about pluralization |
||
|
||
/** | ||
* Remove a child from this container | ||
* | ||
* @param mixed $child | ||
* @return void | ||
*/ | ||
public function removeChild($child) | ||
{ | ||
$this->children->removeElement($child); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Symfony\Cmf\Bundle\BlockBundle\Document; | ||
|
||
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; | ||
use Symfony\Cmf\Bundle\BlockBundle\Document\ContainerBlock; | ||
|
||
/** | ||
* Block that renders a slideshow of child items | ||
* | ||
* @PHPCRODM\Document(referenceable=true) | ||
*/ | ||
class SlideshowBlock extends ContainerBlock | ||
{ | ||
|
||
/** @PHPCRODM\String */ | ||
protected $title; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getType() | ||
{ | ||
return 'symfony_cmf.block.slideshow'; | ||
} | ||
|
||
public function getTitle() { | ||
return $this->title; | ||
} | ||
|
||
public function setTitle($title) { | ||
$this->title = $title; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace Symfony\Cmf\Bundle\BlockBundle\Document; | ||
|
||
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; | ||
use Symfony\Cmf\Bundle\BlockBundle\Document\BaseBlock; | ||
|
||
/** | ||
* Block that acts as an item of a SlideshowBlock | ||
* | ||
* @PHPCRODM\Document(referenceable=true) | ||
*/ | ||
class SlideshowItemBlock extends BaseBlock | ||
{ | ||
|
||
/** | ||
* @PHPCRODM\Child(name="image", cascade="persist") | ||
*/ | ||
protected $image; | ||
|
||
/** @PHPCRODM\String */ | ||
protected $label; | ||
|
||
/** @PHPCRODM\Node */ | ||
protected $node; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getType() | ||
{ | ||
return 'symfony_cmf.block.slideshow_item'; | ||
} | ||
|
||
public function setLabel($label) | ||
{ | ||
$this->label = $label; | ||
} | ||
|
||
public function getLabel() | ||
{ | ||
return $this->label; | ||
} | ||
|
||
public function setImage($image) | ||
{ | ||
if (!$image) { | ||
return; | ||
} elseif ($this->image && $this->image->getFile()) { | ||
// TODO: this is needed due to a bug in PHPCRODM (http://www.doctrine-project.org/jira/browse/PHPCR-98) | ||
// TODO: this can be removed once the bug is fixed | ||
$this->image->getFile()->setFileContent($image->getFile()->getFileContent()); | ||
} else { | ||
$this->image = $image; | ||
} | ||
} | ||
|
||
public function getImage() | ||
{ | ||
return $this->image; | ||
} | ||
|
||
public function getNode() | ||
{ | ||
return $this->node; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,11 @@ | |
<parameters> | ||
<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> | ||
</parameters> | ||
|
||
<services> | ||
|
@@ -24,5 +29,44 @@ | |
<argument>%symfony_cmf_block.content_basepath%</argument> | ||
</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/> | ||
<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_item_admin" class="%symfony_cmf_block.slideshow_item_admin_class%"> | ||
<tag name="sonata.admin" manager_type="doctrine_phpcr" group="dashboard.group_content" label_catalogue="SymfonyCmfBlockBundle" label="dashboard.label_slideshow_item_block" label_translator_strategy="sonata.admin.label.strategy.underscore" /> | ||
<argument/> | ||
<argument>%symfony_cmf_block.slideshow_item_document_class%</argument> | ||
<argument>SonataAdminBundle:CRUD</argument> | ||
|
||
<call method="setRouteBuilder"> | ||
<argument type="service" id="sonata.admin.route.path_info_slashes" /> | ||
</call> | ||
|
||
<call method="setRoot"> | ||
<argument>%symfony_cmf_block.content_basepath%</argument> | ||
</call> | ||
</service> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and this should be slideshow.admin.xml and could have a sub-option to activate sonata admin for the slideshows |
||
|
||
</services> | ||
</container> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i wonder if we could move the reorder behaviour into sonata_type_collection, or maybe a phpcr_sonata_type_collection - as we found out, its quite dangerous when done naively.