Started to use CKEditor 5 as richt text editor.

This commit is contained in:
Jan Böhmer 2022-07-25 01:09:31 +02:00
parent 156301b8a4
commit dbdfe5ea95
9 changed files with 1575 additions and 49 deletions

View file

@ -53,6 +53,7 @@ use App\Entity\PriceInformations\Orderdetail;
use App\Form\AttachmentFormType;
use App\Form\ParameterType;
use App\Form\Type\MasterPictureAttachmentType;
use App\Form\Type\RichTextEditorType;
use App\Form\Type\SIUnitType;
use App\Form\Type\StructuralEntityType;
use App\Form\WorkaroundCollectionType;
@ -63,6 +64,7 @@ use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\ResetType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface;
@ -106,11 +108,11 @@ class PartBaseType extends AbstractType
],
'disabled' => !$this->security->isGranted('name.edit', $part),
])
->add('description', CKEditorType::class, [
->add('description', RichTextEditorType::class, [
'required' => false,
'empty_data' => '',
'label' => 'part.edit.description',
'config_name' => 'description_config',
'mode' => 'single_line',
'attr' => [
'placeholder' => 'part.edit.description.placeholder',
'rows' => 2,
@ -206,12 +208,13 @@ class PartBaseType extends AbstractType
]);
//Comment section
$builder->add('comment', CKEditorType::class, [
$builder->add('comment', RichTextEditorType::class, [
'required' => false,
'label' => 'part.edit.comment',
'attr' => [
'rows' => 4,
],
'disabled' => !$this->security->isGranted('comment.edit', $part),
'empty_data' => '',
]);

View file

@ -0,0 +1,53 @@
<?php
namespace App\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
class RichTextEditorType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver)
{
parent::configureOptions($resolver); // TODO: Change the autogenerated stub
$resolver->setDefault('mode', 'full');
$resolver->setAllowedValues('mode', ['full', 'single_line']);
$resolver->setDefault('output_format', 'markdown');
$resolver->setAllowedValues('output_format', ['markdown']);
}
public function getBlockPrefix()
{
return 'rich_text_editor';
}
public function finishView(FormView $view, FormInterface $form, array $options)
{
$view->vars['attr'] = array_merge($view->vars['attr'], $this->optionsToAttrArray($options));
parent::finishView($view, $form, $options); // TODO: Change the autogenerated stub
}
protected function optionsToAttrArray(array $options)
{
$tmp = [];
$tmp['data-mode'] = $options['mode'];
$tmp['data-output-format'] = $options['output_format'];
//Add our data-controller element to the textarea
$tmp['data-controller'] = 'elements--ckeditor';
return $tmp;
}
public function getParent()
{
return TextareaType::class;
}
}