Search by

codepulse2020 / filament-forms-tinymce

haosheng

A Filament form field that integrates TinyMCE 8 rich text editor with dark mode, profiles, and file browser support.

Package info

github.com/codepulse2020/filament-forms-tinymce

pkg:composer/codepulse2020/filament-forms-tinymce

Statistics

Installs: 10

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v2.1.0 2026-11-30 03:16 UTC

This package is auto-updated.

Last update: 2026-11-30 03:18:01 UTC


README

Latest Version on Packagist GitHub Tests Action Status Total Downloads

A rich-text form field for Filament with TinyMCE 8, editor profiles, and optional media browser integration.

Requirements

  • PHP ^8.2
  • Laravel ^10.0 / ^11.0 / ^12.0 / ^13.0 (Laravel 13 needs PHP 8.3)
  • Filament ^3.0, ^4.0, or ^5.0. Follow the Laravel, PHP, and Livewire requirements of your Filament version.

The release test matrix uses Laravel 12 and 13:

Filament Livewire Laravel 12 Laravel 13 Verification
3 3 PHP 8.4 PHP 8.4 PHP and browser tests
4 3 PHP 8.4 PHP 8.4 PHP and browser tests
5 4 PHP 8.2 and 8.4 PHP 8.3 and 8.4 PHP tests on all, browser tests on 8.4

Laravel 10 and 11 remain accepted where Filament supports them, but they are not part of the current release test matrix. Use a version of the optional media browser that supports your Filament release.

Installation

composer require codepulse2020/filament-forms-tinymce
php artisan filament:assets

To customize the package defaults, publish the config file:

php artisan vendor:publish --tag="filament-forms-tinymce-config"

Usage

Basic

use CodePulse2020\FilamentFormsTinymce\TinyMceEditor;

TinyMceEditor::make('content')

Profiles

Profiles let you define reusable editor presets in the config file. Three built-in profiles are provided: default, simple, and full.

TinyMceEditor::make('content')
    ->profile('simple')

Define your own profiles in the config:

// config/filament-forms-tinymce.php

'profiles' => [
    'blog' => [
        'plugins' => 'lists link image media code',
        'toolbar' => 'blocks | bold italic | link image media | code',
        'menubar' => false,
        'height' => 500,
    ],
],

Priority order: instance method > profile > TinyMCE built-in default

// Profile sets height to 500, but this instance overrides it to 800
TinyMceEditor::make('content')
    ->profile('blog')
    ->height(800)

Editor options

All TinyMCE options can also be set directly via fluent methods without using profiles:

TinyMceEditor::make('content')
    ->toolbar('bold italic underline | bullist numlist | link image media')
    ->plugins('lists link image media table code')
    ->menubar('file edit view insert format')
    ->height(500)
    ->language('zh_TW')
    ->skin('oxide-dark')
    ->contentCss('dark')

For any TinyMCE init option not covered by a dedicated method, use options():

TinyMceEditor::make('content')
    ->options([
        'branding' => false,
        'resize' => true,
        'paste_as_text' => true,
    ])

Regex options (protect)

Pass TinyMCE's protect patterns as "/pattern/flags" strings. The field converts them to JavaScript RegExp objects. Keep patterns limited to known markers because TinyMCE matches them synchronously when content is opened.

'custom_configs' => [
    // Preserve one known mail template marker.
    'protect' => [
        '/\{!! customer_name !!\}/g',
    ],
],

File browser

The file browser integration is enabled by default. When enabled, TinyMCE's file_picker_callback dispatches Livewire events (open-media-browser / media-selected) so you can connect your own media browser component. The receiver must authorize each selected profile, disk, directory, and operation on the server. Treat event parameters as browser input.

Tip: Install codepulse2020/filament-media-browser for a ready-made media browser that works out of the box.

composer require codepulse2020/filament-media-browser

The file browser selects images only. Video and audio are embedded by external URL in the media dialog, which has no browse button for its source.

Disable file browser

TinyMceEditor::make('content')
    ->fileBrowser(false)

Media profile

With filament-media-browser 2.x, choose one of the profiles listed in its config. The profile decides the disk and directory. Without it the browser opens its default profile:

TinyMceEditor::make('content')
    ->mediaProfile('post-images')

->mediaProfile() is unrelated to ->profile(), which selects the editor configuration. The editor stores public URLs, so the profile must be on a disk the browser can serve publicly.

->mediaDisk() and ->mediaDirectory() are deprecated. They still apply to filament-media-browser 1.x and custom receivers. The 2.x browser refuses to open when either is set without ->mediaProfile(), instead of using another location.

URL format

TinyMCE always requests full URLs from the media browser (storeAsUrl: true), regardless of the media browser's global store_as_url setting. The final URL format stored in HTML is controlled by TinyMCE's built-in URL conversion options:

Desired output Configuration
/storage/media/photo.jpg (default) relative_urls: false, remove_script_host: true
http://domain.com/storage/media/photo.jpg relative_urls: false, remove_script_host: false
Keep original URL convert_urls: false

The default profile already includes relative_urls: false and remove_script_host: true, which produces portable absolute paths without the domain.

For email templates that require full URLs (email clients cannot resolve relative paths), use a dedicated profile or override via options():

// Option 1: Use a profile
TinyMceEditor::make('email_body')
    ->profile('email')

// Option 2: Override inline
TinyMceEditor::make('email_body')
    ->options(['remove_script_host' => false])

Merge tags

Insert predefined variables into the editor via a toolbar dropdown — useful for email templates. No TinyMCE Premium required.

Via profile (recommended)

Define merge tags in a profile so all fields using that profile share the same variables:

// config/filament-forms-tinymce.php
'profiles' => [
    'email' => [
        'plugins' => 'lists link image media table code wordcount',
        'toolbar' => 'undo redo | blocks | bold italic | mergetags | link image | removeformat',
        'menubar' => false,
        'height' => 480,
        'mergetags' => [
            ['value' => 'user.name', 'title' => '使用者名稱'],
            ['value' => 'user.email', 'title' => '使用者信箱'],
            ['title' => '網站', 'menu' => [
                ['value' => 'site.name', 'title' => '網站名稱'],
                ['value' => 'site.url', 'title' => '網站網址'],
            ]],
        ],
        'mergetag_prefix' => '{{',  // optional, defaults to '{{'
        'mergetag_suffix' => '}}',  // optional, defaults to '}}'
        'custom_configs' => [
            'relative_urls' => false,
            'remove_script_host' => false,
        ],
    ],
],
TinyMceEditor::make('email_body')
    ->profile('email')

Selecting "使用者名稱" inserts {{user.name}} into the editor.

Via instance methods

Instance methods take priority over profile settings:

TinyMceEditor::make('email_body')
    ->toolbar('undo redo | blocks | bold italic | mergetags | removeformat')
    ->mergetags([
        ['value' => 'user.name', 'title' => 'User Name'],
    ])
    ->mergetagPrefix('${')
    ->mergetagSuffix('}')
// Inserts: ${user.name}

TinyMCE source

By default, TinyMCE is loaded from jsDelivr with an SRI integrity check. No API key is required. To use your own hosted copy instead, set TINYMCE_USE_CDN=false in your application's environment. If you manage a published package config directly, use 'use_cdn' => false. Rebuild the Laravel config cache after changing the setting.

In CDN mode you can customise the URL and version in the config:

'cdn_url' => 'https://cdn.jsdelivr.net/npm/tinymce@{version}/tinymce.min.js',
'version' => '8.10.2',

Update the URL, version, and matching SRI digest together. A preloaded TinyMCE global must match a configured exact version. If loading or initialization fails, edits to the HTML fallback stay in a draft on the current page. Standard form submission waits until the editor can load and process that draft.

Self-hosting without a CDN

In your application's build, install the same TinyMCE version as the PHP version setting, then copy the entire distribution into the public directory. Copy the language packs if you use a non-English editor interface:

npm install --save-exact tinymce@8.10.2 tinymce-i18n@26.11.2
mkdir -p public/vendor/tinymce/8.10.2/langs
cp -R node_modules/tinymce/. public/vendor/tinymce/8.10.2/
cp node_modules/tinymce-i18n/langs8/zh-TW.js public/vendor/tinymce/8.10.2/langs/

Deploy these files with the app. The default local_asset_path is /vendor/tinymce/{version}. You can change it to another same-origin absolute path, including a path prefix if your app is served under one. The script, bundled plugins, themes, icons, skins, and configured locale then load from that directory. Do not separately preload a different distribution in the panel. The CDN integrity and crossorigin settings are not used for self-hosted assets, and missing local files never trigger a CDN fallback.

This controls the package's own assets. If you need a page with no outbound requests, also self-host any custom plugins, language packs, styles, fonts, or media referenced by the application or editor content. See TinyMCE's asset options and localization options.

Upgrading from 1.x

Replace the Composer package and the namespace. Both packages cannot be installed together:

composer remove haosheng0211/filament-forms-tinymce --no-update
composer require codepulse2020/filament-forms-tinymce:^2.0
php artisan filament:assets

Replace MrJin\FilamentFormsTinymce with CodePulse2020\FilamentFormsTinymce in your code. If your application stores field class names, for example in a JSON column that selects form fields, update the stored values in the same deployment.

Update the package through Composer and refresh the published frontend asset with php artisan filament:assets. If you previously published the package configuration, merge the new version and integrity values into it together and rebuild any configuration cache. Self-hosted deployments should publish the corresponding versioned asset directory before switching the configuration. Preserve your repository-specific profiles. Replace any general-purpose protect expressions with known markers, then reopen representative existing records before rollout.

When moving to filament-media-browser 2.x, replace ->mediaDisk() and ->mediaDirectory() with ->mediaProfile().

When upgrading Filament, select a compatible version of the media browser in the same rollout and check its authorization configuration. Core editor usage requires no media package when fileBrowser(false) is configured. Use server-side HTML filtering where your application accepts or renders author-provided HTML.

Config reference

return [
    'use_cdn' => env('TINYMCE_USE_CDN', true),
    'local_asset_path' => '/vendor/tinymce/{version}',
    'cdn_url' => 'https://cdn.jsdelivr.net/npm/tinymce@{version}/tinymce.min.js',
    'version' => '8.10.2',

    // SRI hash for CDN (set to null to disable)
    'integrity' => 'sha384-...',
    'crossorigin' => 'anonymous',

    // Profiles (pre-defined editor configurations)
    'profiles' => [
        'default' => [
            'plugins' => 'lists link image media table code wordcount',
            'toolbar' => 'undo redo | blocks | bold italic underline strikethrough | ...',
            'menubar' => false,
            'height' => 480,
            'custom_configs' => [
                'relative_urls' => false,
                'remove_script_host' => true,
            ],
        ],
        'simple' => [ /* ... */ ],
        'full'   => [ /* ... */ ],
        // 'email' => [
        //     'custom_configs' => [
        //         'relative_urls' => false,
        //         'remove_script_host' => false,
        //     ],
        // ],
    ],
];

Testing

composer test

To run the browser tests against the current Composer installation:

npm ci
npx playwright install chromium
php vendor/bin/testbench filament:assets
npm run test:browser

Changelog

Please see CHANGELOG for more information on what has changed recently.

Security Vulnerabilities

See the security policy for private reporting and dependency update guidance.

Credits

License

The MIT License (MIT). Please see License File for more information.