Browse Source

backports murph-skeleton

develop
Simon Vieille 2 weeks ago
parent
commit
c8a200867a
  1. 21
      core/Entity/Site/Page/ChoiceBlock.php
  2. 44
      core/Event/Page/PageEditEvent.php
  3. 32
      core/Form/Site/Page/ChoiceBlockType.php
  4. 33
      core/Form/Site/Page/FilePickerBlockType.php

21
core/Entity/Site/Page/ChoiceBlock.php

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

44
core/Event/Page/PageEditEvent.php

@ -0,0 +1,44 @@
<?php
namespace App\Core\Event\Page;
use Symfony\Contracts\EventDispatcher\Event;
use App\Core\Entity\Site\Page\Page;
/**
* class PageEditEvent.
*
* @author Simon Vieille <simon@deblan.fr>
*/
class PageEditEvent extends Event
{
const FORM_INIT_EVENT = 'page_edit_event.form_init';
protected Page $page;
protected array $pageBuilderOptions = [];
public function __construct(Page $page)
{
$this->page = $page;
}
public function getPage()
{
return $this->page;
}
public function getPageBuilderOptions(): array
{
return $this->pageBuilderOptions;
}
public function addPageBuilderOptions(array $options): self
{
$this->pageBuilderOptions = array_merge(
$this->pageBuilderOptions,
$options
);
return $this;
}
}

32
core/Form/Site/Page/ChoiceBlockType.php

@ -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' => [],
]);
}
}

33
core/Form/Site/Page/FilePickerBlockType.php

@ -0,0 +1,33 @@
<?php
namespace App\Core\Form\Site\Page;
use App\Core\Form\FileManager\FilePickerType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\AbstractType;
use App\Core\Entity\Site\Page\Block;
class FilePickerBlockType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'value',
FilePickerType::class,
array_merge([
'required' => false,
'label' => false,
], $options['options']),
);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Block::class,
'block_prefix' => 'file_picker_page_block',
'options' => [],
]);
}
}
Loading…
Cancel
Save