add SimpleMdTextareaType::class

This commit is contained in:
Simon Vieille 2022-03-25 12:18:53 +01:00
parent 559afad7d3
commit 96ea6ed486
3 changed files with 49 additions and 3 deletions

View file

@ -4,7 +4,7 @@ namespace App\Entity\Page;
use App\Core\Entity\Site\Page\Block;
use App\Core\Entity\Site\Page\FileBlock;
use App\Core\Form\Site\Page\TextareaBlockType;
use App\Form\Type\SimpleMdTextareaBlockType;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Form\FormBuilderInterface;
@ -19,12 +19,11 @@ class SimplePage extends TitledPage
$builder->add(
'content',
TextareaBlockType::class,
SimpleMdTextareaBlockType::class,
[
'label' => 'Contenu',
'options' => [
'attr' => [
'data-simplemde' => '',
'rows' => '50',
],
'constraints' => [

View file

@ -0,0 +1,21 @@
<?php
namespace App\Form\Type;
use App\Core\Form\Site\Page\TextBlockType;
use Symfony\Component\Form\FormBuilderInterface;
class SimpleMdTextareaBlockType extends TextBlockType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'value',
SimpleMdTextareaType::class,
array_merge([
'required' => false,
'label' => false,
], $options['options']),
);
}
}

View file

@ -0,0 +1,26 @@
<?php
namespace App\Form\Type;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
class SimpleMdTextareaType extends TextareaType
{
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
if (!isset($view->vars['attr']['data-simplemde'])) {
$view->vars['attr']['data-simplemde'] = '';
}
if (!isset($view->vars['attr']['rows'])) {
$view->vars['attr']['rows'] = 20;
}
return parent::buildView($view, $form, $options);
}
}