add ChoiceBlockType and ChoiceBlock
This commit is contained in:
parent
5ed1d0d114
commit
a7c1824f23
21
core/Entity/Site/Page/ChoiceBlock.php
Normal file
21
core/Entity/Site/Page/ChoiceBlock.php
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Core\Entity\Site\Page;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Entity
|
||||||
|
*/
|
||||||
|
class ChoiceBlock extends Block
|
||||||
|
{
|
||||||
|
public function getValue()
|
||||||
|
{
|
||||||
|
return json_decode(parent::getValue(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setValue($value): self
|
||||||
|
{
|
||||||
|
return parent::setValue(json_encode($value));
|
||||||
|
}
|
||||||
|
}
|
32
core/Form/Site/Page/ChoiceBlockType.php
Normal file
32
core/Form/Site/Page/ChoiceBlockType.php
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Core\Form\Site\Page;
|
||||||
|
|
||||||
|
use App\Core\Entity\Site\Page\ChoiceBlock;
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
|
class ChoiceBlockType extends AbstractType
|
||||||
|
{
|
||||||
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
|
{
|
||||||
|
$builder->add(
|
||||||
|
'value',
|
||||||
|
ChoiceType::class,
|
||||||
|
array_merge([
|
||||||
|
'required' => false,
|
||||||
|
'label' => false,
|
||||||
|
], $options['options']),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
|
{
|
||||||
|
$resolver->setDefaults([
|
||||||
|
'data_class' => ChoiceBlock::class,
|
||||||
|
'options' => [],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue