38 lines
1 KiB
PHP
38 lines
1 KiB
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(),
|
|
array(
|
|
'attr' => array(
|
|
'class' => 'embeded-form',
|
|
),
|
|
)
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|