mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53: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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -7,9 +7,8 @@ buildCKEditor = function(encore)
|
||||
.addPlugin( new CKEditorWebpackPlugin( {
|
||||
language: 'fr',
|
||||
addMainLanguageTranslationsToAllAssets: true,
|
||||
verbose: true,
|
||||
strict: true,
|
||||
//additionalLanguages: ['en', 'nl', 'es'],
|
||||
verbose: !encore.isProduction(),
|
||||
strict: true
|
||||
} ) )
|
||||
|
||||
// Use raw-loader for CKEditor 5 SVG files.
|
||||
@@ -35,7 +34,7 @@ buildCKEditor = function(encore)
|
||||
} )
|
||||
} )
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
// Compile and loads all assets from the Chill Main Bundle
|
||||
module.exports = function(encore, entries)
|
||||
|
@@ -138,10 +138,6 @@ services:
|
||||
tags:
|
||||
- { name: form.type }
|
||||
|
||||
Chill\MainBundle\Form\Extension\CKEditorExtension:
|
||||
tags:
|
||||
- { name: form.type_extension, extended_type: Symfony\Component\Form\Extension\Core\Type\TextareaType }
|
||||
|
||||
chill.main.form.type.comment:
|
||||
class: Chill\MainBundle\Form\Type\CommentType
|
||||
arguments:
|
||||
|
Reference in New Issue
Block a user