Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

SlideshowBlock #32

Merged
merged 38 commits into from Mar 15, 2013
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
228becd
initial slideshowblock
Feb 11, 2013
c792236
added removeChild method so we can create an adminclass
Feb 11, 2013
34ec2c1
added title and path properties
Feb 11, 2013
15103ad
sonata admin passes the instance, not the id
Feb 13, 2013
a6c9f56
added admin classes for slideshow
Feb 19, 2013
e77bbf4
added reordering
Feb 21, 2013
05e9870
Merge remote-tracking branch 'origin/master' into slideshow
Feb 21, 2013
24f298f
added image to admin and template
Feb 22, 2013
e3a8562
namespace was changed
Feb 22, 2013
0a31b0a
indentation
Feb 22, 2013
7a38394
updated todos
Feb 22, 2013
dbbdbde
adapted containerblock so new items can be added with sonata
Feb 22, 2013
b6a46c1
corrected logic to determine if we're in edit or create mode
Feb 25, 2013
3fc4a54
never return null
Feb 27, 2013
2c9ed21
added TODO, corrected name
Feb 27, 2013
f8e2d13
removed unneeded property. allow extending classes as slides
Feb 27, 2013
04ee009
path prop doesnt exist anymore
Feb 27, 2013
0600ff1
removed custom service for slideshows and reuse ContainerBlockService…
Mar 1, 2013
0ebf3db
added second admin class for inline slideshow editing (MinimalSlidesh…
Mar 1, 2013
76fddb6
updated TODO, cs
Mar 1, 2013
4147e76
optional dependency on imagine bundle
Mar 5, 2013
4f56451
Merge remote-tracking branch 'origin/master' into slideshow
Mar 5, 2013
57bda6e
missing close tag
Mar 5, 2013
be0c58d
Merge remote-tracking branch 'origin/master' into slideshow
Mar 6, 2013
84e2de9
fix resorting to no longer break add and delete, generate document names
dbu Mar 13, 2013
37ab49e
make slideshow optional and root path configurable
dbu Mar 13, 2013
0b2ecc3
Merge branch 'master' into slideshow
Mar 14, 2013
97f58ef
added MultilangSlideshowItemBlock
Mar 14, 2013
f728d66
added translations (de still missing)
Mar 14, 2013
ccc23c3
secure check
Mar 14, 2013
ec8bc07
Merge branch 'master' into slideshow
Mar 15, 2013
bc85342
rename SlideshowItemBlock to ImageBlock
Mar 15, 2013
6aeacfb
remove duplicated code
Mar 15, 2013
ad4a92d
renaming slideshow stuff
Mar 15, 2013
e98ffe5
update translations
Mar 15, 2013
305b2c6
some cleanups
dbu Mar 15, 2013
476631a
proper naming for Admin classes
Mar 15, 2013
183bc29
only display block title when it is defined
Mar 15, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 66 additions & 0 deletions Admin/MinimalSlideshowAdmin.php
@@ -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',
Copy link
Member

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.

))
->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?
Copy link
Member

Choose a reason for hiding this comment

The 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


}
21 changes: 21 additions & 0 deletions Admin/SlideshowAdmin.php
@@ -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();
}
}
25 changes: 25 additions & 0 deletions Admin/SlideshowItemAdmin.php
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is still a TODO

Copy link
Member

Choose a reason for hiding this comment

The 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();
}
}
12 changes: 10 additions & 2 deletions Block/ContainerBlockService.php
Expand Up @@ -15,16 +15,23 @@ class ContainerBlockService extends BaseBlockService implements BlockServiceInte
{

protected $blockRenderer;
protected $template = 'SymfonyCmfBlockBundle:Block:block_container.html.twig';

/**
* @param string $name
* @param \Symfony\Bundle\FrameworkBundle\Templating\EngineInterface $templating
* @param \Sonata\BlockBundle\Block\BlockRendererInterface $blockRenderer
* @param string|null $template
*/
public function __construct($name, EngineInterface $templating, BlockRendererInterface $blockRenderer)
public function __construct($name, EngineInterface $templating, BlockRendererInterface $blockRenderer, $template = null)
{
parent::__construct($name, $templating);

$this->blockRenderer = $blockRenderer;

if ($template) {
$this->template = $template;
}
}

/**
Expand All @@ -48,7 +55,7 @@ public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
*/
protected function getTemplate()
{
return 'SymfonyCmfBlockBundle:Block:block_container.html.twig';
return $this->template;
}

/**
Expand All @@ -73,6 +80,7 @@ public function execute(BlockInterface $block, Response $response = null)
}

return $this->renderResponse($this->getTemplate(), array(
'block' => $block,
'childBlocks' => $childBlocks,
'settings' => $settings
), $response);
Expand Down
2 changes: 1 addition & 1 deletion Document/BaseBlock.php
Expand Up @@ -290,7 +290,7 @@ public function getTtl()
*/
public function __toString()
{
return $this->name;
return $this->name ? $this->name : '';
}

/**
Expand Down
31 changes: 23 additions & 8 deletions Document/ContainerBlock.php
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh? should $children not be a list of children here?

Copy link
Member

Choose a reason for hiding this comment

The 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);
}

}
35 changes: 35 additions & 0 deletions Document/SlideshowBlock.php
@@ -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;
}

}
68 changes: 68 additions & 0 deletions Document/SlideshowItemBlock.php
@@ -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;
}

}
44 changes: 44 additions & 0 deletions Resources/config/admin.xml
Expand Up @@ -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>
Expand All @@ -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>
Copy link
Member

Choose a reason for hiding this comment

The 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>