Skip to content

Setup: Richeditor

dante di domenico edited this page Jun 23, 2025 · 1 revision

Edit configuration

Richeditor configuration provides customization for TinyMCE v5 instances in manager.

You can set Richeditor in config/app_local.php (or in config/projects/<projectName>.php if you use multi project configuration).

Richtext configuration

Richtext configuration let you customize the rich text editor toolbar and configuration for specific fields.

Example:

'Richeditor' => [
    'style_formats' => [
        [
            'title' => 'Custom Blocks',
            'items' => [
                ['title' => 'Highlight', 'block' => 'div', 'classes' => ['be-highlight']],
            ],
        ],
    ],
    'style_formats_merge' => true,
    'content_style' => '.be-highlight { background-color: #F6F6F6; }',
    'cleanup_regex_pattern' => '\\sstyle="[^"]*"', // remove style attributes from tags
    'cleanup_regex_argument' => 'gs', // global and match new lines
    'cleanup_regex_replace' => '', // replace with empty string
    'fields_regex_map' => [
        'title' => [ // cleanup title field from unwanted tags
            'cleanup_regex_pattern' => '<(?!/?(em|sub|sup)\\b)[^>]+>',
            'cleanup_regex_argument' => 'gi',
            'cleanup_regex_replacement' => '',
        ],
    ],
],

You can override style_formats, style_formats_merge, content_style to customize the rich text editor behavior.

Special keys cleanup_regex_pattern, cleanup_regex_argument, cleanup_regex_replace and fields_regex_map can be used for advanced customization, to handle field change events.

cleanup* keys allow you to specify a regex pattern to clean up unwanted tags or attributes from the content, on every richtext field change.

With fields_regex_map you can specify regex patterns for specific fields to clean up unwanted tags or attributes, on field change.

Clone this wiki locally