Permalink
Browse files

Store List data serialized

  • Loading branch information...
rvanlaarhoven committed Jan 25, 2016
1 parent 38d1831 commit 9735c6f10ba615c29c6c9e1b5f10acaa3ffc12a2
@@ -195,6 +195,13 @@ public function postRemove(BlockInterface $block)
{
}
/**
* {@inheritdoc}
*/
public function postLoad(BlockInterface $block)
{
}
/**
* {@inheritdoc}
*/
@@ -246,6 +253,4 @@ public function renderResponse($view, array $parameters = array(), Response $res
{
return $this->getTemplating()->renderResponse($view, $parameters, $response);
}
}
}
View
@@ -217,6 +217,7 @@ public function revert(BlockInterface $block, $rootVersion)
$block->accept(new SortVisitor());
}
$this->getService($block)->postLoad($block);
}
/**
@@ -8,8 +8,7 @@
use Opifer\ContentBundle\Block\BlockServiceInterface;
use Opifer\ContentBundle\Block\Tool\ContentTool;
use Opifer\ContentBundle\Block\Tool\ToolsetMemberInterface;
use Opifer\ContentBundle\Entity\BlockContent;
use Opifer\ContentBundle\Entity\ContentCollectionBlock;
use Opifer\ContentBundle\Entity\ListBlock;
use Opifer\ContentBundle\Model\BlockInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
@@ -21,7 +20,7 @@
/**
* Content Collection Block Service
*/
class ContentCollectionBlockService extends AbstractBlockService implements BlockServiceInterface, ToolsetMemberInterface
class ListBlockService extends AbstractBlockService implements BlockServiceInterface, ToolsetMemberInterface
{
/** @var EntityManager */
protected $em;
@@ -44,7 +43,7 @@ public function __construct(EngineInterface $templating, EntityManager $em)
*/
public function getName(BlockInterface $block = null)
{
return 'Content Collection';
return 'List';
}
/**
@@ -57,66 +56,47 @@ public function buildManageForm(FormBuilderInterface $builder, array $options)
// Default panel
$builder->add(
$builder->create('default', 'form', ['virtual' => true])
->add('blockContentCollection', 'content_list_picker', [
->add('value', 'content_list_picker', [
'label' => 'collection',
'multiple' => true,
'property' => 'title',
'class' => 'Opifer\CmsBundle\Entity\Content',
'data' => $options['data']->getBlockContentCollection()
'data' => $options['data']->getValue()
])
);
}
public function postLoad(BlockInterface $block)
{
$collection = $this->em->getRepository('OpiferCmsBundle:Content')
->createQueryBuilder('c')
->where('c.id IN (:ids)')->setParameter('ids', json_decode($block->getValue()))
->getQuery()
->getResult();
if ($collection) {
$block->setCollection($collection);
}
}
/**
* {@inheritDoc}
*/
public function createBlock()
{
return new ContentCollectionBlock();
return new ListBlock();
}
/**
* {@inheritDoc}
*/
public function getTool()
{
$tool = new ContentTool('Content Collection', 'OpiferContentBundle:ContentCollectionBlock');
$tool = new ContentTool('List', 'OpiferContentBundle:ListBlock');
$tool->setIcon('view_list')
->setDescription('Adds references to a collection of content items');
return $tool;
}
/**
* {@inheritdoc}
*/
public function preFormSubmit(BlockInterface $block)
{
$this->originalCollection = new ArrayCollection();
/** @var ContentCollectionBlock $block */
foreach ($block->getBlockContentCollection() as $blockContent) {
$this->originalCollection->add($blockContent);
}
}
/**
* {@inheritdoc}
*/
public function postFormSubmit(FormInterface $form, BlockInterface $block)
{
/** @var BlockContent $blockContent */
foreach ($form->get('default')->get('blockContentCollection')->getData() as $blockContent) {
$blockContent->setBlock($block);
}
/** @var BlockContent $blockContent */
foreach ($this->originalCollection as $blockContent) {
/** @var ContentCollectionBlock $block */
if (false === $block->getBlockContentCollection()->contains($blockContent)) {
$block->getBlockContentCollection()->removeElement($blockContent);
$this->em->remove($blockContent);
}
}
}
}
View

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 9735c6f

Please sign in to comment.