mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
use ckeditor in custom type
This commit is contained in:
@@ -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'
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
51
src/Bundle/ChillMainBundle/Form/Type/ChillTextareaType.php
Normal file
51
src/Bundle/ChillMainBundle/Form/Type/ChillTextareaType.php
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user