deblan.tv/vendor/trinity/src/Trinity/Bundle/NewsletterBundle/Form/EventListener/AddBlockFieldsSubscriber.php
2016-06-20 11:37:14 +02:00

30 lines
844 B
PHP

<?php
namespace Trinity\Bundle\NewsletterBundle\Form\EventListener;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class AddBlockFieldsSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return array(FormEvents::PRE_SET_DATA => 'preSetData');
}
public function preSetData(FormEvent $event)
{
$data = $event->getData();
$form = $event->getForm();
if ($data && $data->getId()) {
foreach ($data->getConfiguration()->getBlocks() as $block_configuration) {
$type = $block_configuration->getType();
$form->add(sprintf('block_%s', $block_configuration->getName()), new $type());
}
}
}
}