use ckeditor in custom type

This commit is contained in:
2021-03-22 13:45:16 +01:00
parent 7a0f7a4933
commit 28a2c0ea0b
6 changed files with 57 additions and 57 deletions

View File

@@ -1,38 +0,0 @@
<?php
namespace Chill\MainBundle\Form\Extension;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Class CKEditorTypeExtension
*
* @package Chill\MainBundle\Form\Extension
* @author Mathieu Jaumotte mathieu.jaumotte@champs-libres.coop
*/
class CKEditorExtension extends AbstractTypeExtension
{
/**
* Return the class of the Textarea Type being extended.
* @return iterable
*/
public static function getExtendedTypes(): iterable
{
return [TextareaType::class];
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'attr' => [
'class' => 'ckeditor snippet-markdown'
]
]);
}
}

View File

@@ -0,0 +1,51 @@
<?php
/*
* Copyright (C) 2017 Champs Libres Cooperative <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\MainBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormInterface;
/**
*
*
*/
class ChillTextareaType extends AbstractType
{
public function getParent()
{
return TextareaType::class;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefined('disable_editor')
->setDefault('disable_editor', false)
->setAllowedTypes('disable_editor', 'bool');
}
public function buildView(FormView $view, FormInterface $form, array $options)
{
if (!$options['disable_editor']) {
$view->vars['attr']['ckeditor'] = true;
}
}
}