use ckeditor in custom type

This commit is contained in:
Julien Fastré 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;
}
}
}

View File

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

View File

@ -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:

View File

@ -36,6 +36,7 @@ use Chill\CustomFieldsBundle\Form\Type\CustomFieldType;
use Chill\PersonBundle\Form\Type\Select2MaritalStatusType;
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
use Chill\PersonBundle\Form\Type\PersonAltNameType;
use Chill\MainBundle\Form\Type\ChillTextareaType;
class PersonType extends AbstractType
{
@ -89,7 +90,7 @@ class PersonType extends AbstractType
if ($this->config['memo'] === 'visible') {
$builder
->add('memo', TextareaType::class, array('required' => false))
->add('memo', ChillTextareaType::class, array('required' => false))
;
}
@ -98,7 +99,7 @@ class PersonType extends AbstractType
}
if ($this->config['contact_info'] === 'visible') {
$builder->add('contactInfo', TextareaType::class, array('required' => false));
$builder->add('contactInfo', ChillTextareaType::class, array('required' => false));
}
if ($this->config['phonenumber'] === 'visible') {

View File

@ -53,15 +53,6 @@ This view should receive those arguments:
{% apply markdown_to_html %}
{{ person.memo }}
{% endapply %}<br>
{% apply markdown_to_html %}
## Marc est down
**michel** _ça va_
> une citation
Sit amet nisl ~~purus~~ in mollis.
{% endapply %}
</div>
{% endif %}