| Install | |
|---|---|
composer require iamgerwin/filament-tinymce |
|
| Latest Version: | v1.0.0 |
| PHP: | ^8.3 |
A powerful and flexible TinyMCE rich text editor field for Filament v3, featuring comprehensive customization options, image uploads, dark mode support, and multiple editor profiles.
You can install the package via composer:
composer require iamgerwin/filament-tinymce
Publish the configuration file:
php artisan vendor:publish --tag="filament-tinymce-config"
Optionally, publish the assets:
php artisan vendor:publish --tag="filament-tinymce-assets"
To use TinyMCE cloud, add your API key to your .env file:
TINYMCE_API_KEY=your-api-key-here
TINYMCE_CLOUD_CHANNEL=6
You can get a free API key from TinyMCE.
The configuration file config/filament-tinymce.php provides extensive customization options:
return [
'api_key' => env('TINYMCE_API_KEY', ''),
'cloud_channel' => env('TINYMCE_CLOUD_CHANNEL', '6'),
'show_menu_bar' => false,
'min_height' => 256,
'max_height' => 0, // 0 = no limit
'plugins' => [
'advlist', 'anchor', 'autolink', 'autoresize', 'autosave',
'charmap', 'code', 'codesample', 'directionality', 'emoticons',
'fullscreen', 'help', 'image', 'insertdatetime', 'link',
'lists', 'media', 'pagebreak', 'preview', 'quickbars',
'searchreplace', 'table', 'visualblocks', 'visualchars', 'wordcount'
],
'toolbar' => [
'undo redo restoredraft | styles | bold italic underline strikethrough',
'alignleft aligncenter alignright alignjustify | outdent indent',
'blocks fontfamily fontsize | forecolor backcolor',
'bullist numlist | link image media table | code fullscreen preview'
],
'upload_images' => [
'enabled' => false,
'disk' => 'public',
'folder' => 'images',
'max_size' => 2048, // in KB
],
// Pre-configured profiles
'profiles' => [
'simple' => [...],
'standard' => [...],
'full' => [...]
]
];
use Iamgerwin\FilamentTinymce\Forms\Components\TinymceEditor;
TinymceEditor::make('content')
->label('Content')
->required()
For basic text editing needs:
TinymceEditor::make('description')
->simple()
Enable image uploads with custom configuration:
TinymceEditor::make('content')
->uploadImages()
->uploadDisk('s3')
->uploadDirectory('blog/images')
->uploadMaxSize(4096) // 4MB
TinymceEditor::make('content')
->plugins(['link', 'image', 'code', 'table'])
->toolbar([
'undo redo | bold italic underline',
'link image table | code'
])
->showMenuBar()
TinymceEditor::make('content')
->minHeight(400)
->maxHeight(800)
TinymceEditor::make('content')
->apiKey('your-custom-api-key')
->cloudChannel('7')
->init([
'branding' => false,
'promotion' => false,
'browser_spellcheck' => true,
'paste_as_text' => true,
'autosave_interval' => '30s',
'autosave_retention' => '60m',
'content_style' => 'body { font-family: Arial; font-size: 16px; }'
])
namespace App\Filament\Resources\PostResource\Pages;
use App\Filament\Resources\PostResource;
use Filament\Resources\Pages\CreateRecord;
use Iamgerwin\FilamentTinymce\Forms\Components\TinymceEditor;
class CreatePost extends CreateRecord
{
protected static string $resource = PostResource::class;
protected function getFormSchema(): array
{
return [
Forms\Components\TextInput::make('title')
->required()
->maxLength(255),
TinymceEditor::make('content')
->label('Post Content')
->required()
->uploadImages()
->uploadDirectory('posts/' . date('Y/m'))
->minHeight(500),
Forms\Components\Toggle::make('is_published')
->label('Publish immediately')
];
}
}
The field works seamlessly with Laravel's validation rules:
TinymceEditor::make('content')
->required()
->minLength(100)
->maxLength(5000)
->rules(['string', 'max:5000'])
TinymceEditor::make('content')
->disabled()
// or
->readonly()
// or conditionally
->disabled(fn () => ! auth()->user()->isAdmin())
The editor automatically adapts to Filament's dark mode. No additional configuration needed.
Configure autosave functionality:
TinymceEditor::make('content')
->init([
'autosave_interval' => '20s',
'autosave_retention' => '30m',
'autosave_restore_when_empty' => true,
])
Apply custom styles to the editor content:
TinymceEditor::make('content')
->init([
'content_style' => '
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
line-height: 1.6;
color: #333;
}
h1 { color: #2563eb; }
blockquote {
border-left: 4px solid #e5e7eb;
padding-left: 1rem;
color: #6b7280;
}
'
])
Different configuration for mobile devices:
TinymceEditor::make('content')
->init([
'mobile' => [
'menubar' => false,
'plugins' => 'autosave lists link image',
'toolbar' => 'undo bold italic styles link image',
]
])
When enabling image uploads, the package includes:
Configure in your config/filament-tinymce.php:
'upload_images' => [
'enabled' => true,
'disk' => 's3', // or 'local', 'public'
'folder' => 'uploads/tinymce',
'max_size' => 2048, // KB
],
Run the test suite:
composer test
Run tests with coverage:
composer test-coverage
Run PHPStan analysis:
./vendor/bin/phpstan analyse
Format code with Pint:
composer format
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
This package is inspired by Nova4-TinymceEditor and uses the Spatie Laravel Package Skeleton.
The MIT License (MIT). Please see License File for more information.