:navigation-title: Frontend rich text editor .. include:: /Includes.rst.txt .. _frontend-rich-text-editor: ===================================== Rich text editor in the frontend form ===================================== .. versionadded:: 11.2.0 Textarea elements of the event form based on EXT:form can be edited with a CKEditor 5. Textarea elements of the event form based on EXT:form (site setting `events2.form.useExtForm`) can be edited with a small CKEditor 5. Frontend users can format the text, and formatting added by editors in the backend is kept when the event is edited in the frontend. By default, the element `detail-description` (column `detail_information`) gets the editor. Further elements can be added by configuration. The feature is disabled by default. Without it, all elements are plain textareas as before. .. contents:: :caption: Table of contents :local: .. _frontend-rich-text-editor-requirements: Requirements for the frontend rich text editor ============================================== * The event form based on EXT:form (site setting `events2.form.useExtForm`). * The system extension EXT:rte_ckeditor (:composer:`typo3/cms-rte-ckeditor`). The editor is not activated if it is not installed. No build step (npm, webpack) is needed. The CKEditor 5 ES modules, translations and styles shipped with EXT:rte_ckeditor are used. .. _frontend-rich-text-editor-site-settings: Site settings of the frontend rich text editor ============================================== The following settings are provided by the site set `jweiland/events2` and are available in TypoScript as :typoscript:`plugin.tx_events2.settings.new.richText`, see :ref:`typoscript-new-richtext-enable`. .. confval-menu:: :name: events2-rich-text-settings :display: table :type: :default: .. confval:: events2.form.richText.enable :name: events2-form-richtext-enable :type: bool :default: `false` Use CKEditor 5 of EXT:rte_ckeditor for the rich text elements of the event form based on EXT:form. .. confval:: events2.form.richText.elements :name: events2-form-richtext-elements :type: string :default: `detail-description` Comma-separated identifiers of the form elements which get the rich text editor. Elements with :yaml:`dataType: richText` in their :yaml:`dbMapping` get the editor, too. .. _frontend-rich-text-editor-enable: Enable the frontend rich text editor ==================================== Enable the site setting :confval:`events2.form.richText.enable ` of the site set `jweiland/events2`. That is all for the description: the element `detail-description` is the default of the site setting :confval:`events2.form.richText.elements `. This works for overridden copies of :file:`NewEvent.form.yaml` as well, as long as they use this identifier. .. _frontend-rich-text-editor-example-description: Example: Enable the rich text editor for the description -------------------------------------------------------- .. code-block:: yaml :caption: config/sites//settings.yaml events2: form: richText: enable: true .. _frontend-rich-text-editor-elements: Rich text elements of the event form ==================================== An element of the form is a rich text element if * its identifier is listed in the site setting :confval:`events2.form.richText.elements ` or * it has :yaml:`dataType: richText` in its :yaml:`dbMapping`. If the editor is enabled, events2 configures each rich text element automatically: * The :yaml:`dataType` of the element is :yaml:`richText`, so the edit form gets the stored HTML instead of plain text. * The mapping of the element in the `SaveEventFinisher` gets :yaml:`sanitizeRichText: true` (instead of :yaml:`convertPlainTextToHtml` or :yaml:`normalizePlainText`). * While rendering, the textarea gets the attribute :html:`data-events2-rich-text` with the options of the editor, including the allowed tags of its column (see :ref:`frontend-rich-text-editor-toolbar`). The assets are only loaded on pages of the form which contain a rich text element. Each textarea gets its own editor. If the editor is disabled, rich text elements fall back to plain text: :yaml:`dataType: plainText` and :yaml:`convertPlainTextToHtml` instead of :yaml:`sanitizeRichText`. .. important:: The database column of a rich text element should be a rich text field in TCA (:php:`'enableRichtext' => true`), like `detail_information`. Otherwise, the backend shows the HTML source of the value. The column `teaser`, for example, is a plain text field with a maximum of 255 characters and is **not** a suitable target, unless you change its TCA. The editor of an element is configured for the column :yaml:`properties.dbMapping.column` of the table :yaml:`properties.dbMapping.table`. The table is optional and defaults to `tx_events2_domain_model_event`. Set it only for elements which are stored in another table, so the toolbar matches the allowed tags of that column. Use the same table as the mapping of the element in the `SaveEventFinisher`: .. code-block:: yaml :caption: EXT:my_sitepackage/Configuration/Form/NewEvent.form.yaml (excerpt) - label: 'Notes of the organizer' type: Textarea identifier: organizer-notes properties: dbMapping: table: tx_events2_domain_model_organizer column: tx_myext_notes dataType: richText .. _frontend-rich-text-editor-example-additional-element: Example: Add a rich text editor to an additional form element ------------------------------------------------------------- Add an own textarea to your copy of :file:`NewEvent.form.yaml` and map it to an own column of the event table, which you have configured with :php:`'enableRichtext' => true` in TCA: .. code-block:: yaml :caption: EXT:my_sitepackage/Configuration/Form/NewEvent.form.yaml (excerpt) - label: 'Program' type: Textarea identifier: program properties: dbMapping: column: tx_myext_program # Optional: Instead of listing "program" in the site setting dataType: richText Map the element in the `SaveEventFinisher` options of the table `tx_events2_domain_model_event`: .. code-block:: yaml :caption: EXT:my_sitepackage/Configuration/Form/NewEvent.form.yaml (excerpt) finishers: 1: identifier: SaveEventFinisher options: 4: table: tx_events2_domain_model_event elements: program: mapOnDatabaseColumn: tx_myext_program Then either keep :yaml:`dataType: richText` in the form definition or add the identifier to the site setting: .. code-block:: yaml :caption: config/sites//settings.yaml events2: form: richText: enable: true elements: 'detail-description, program' .. _frontend-rich-text-editor-assets: Loaded files of the frontend rich text editor ============================================= The import map of the CKEditor modules is defined in :file:`EXT:events2/Configuration/JavaScriptModules.php` and rendered by the :php:`PageRenderer` of TYPO3 (:html:`