PHP code example of iamgerwin / filament-tinymce

1. Go to this page and download the library: Download iamgerwin/filament-tinymce library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

iamgerwin / filament-tinymce example snippets


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')
    ->

TinymceEditor::make('description')
    ->simple()

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')
                ->

TinymceEditor::make('content')
    ->(5000)
    ->rules(['string', 'max:5000'])

TinymceEditor::make('content')
    ->disabled()
    // or
    ->readonly()
    // or conditionally
    ->disabled(fn () => ! auth()->user()->isAdmin())

TinymceEditor::make('content')
    ->init([
        'autosave_interval' => '20s',
        'autosave_retention' => '30m',
        'autosave_restore_when_empty' => true,
    ])

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;
            }
        '
    ])

TinymceEditor::make('content')
    ->init([
        'mobile' => [
            'menubar' => false,
            'plugins' => 'autosave lists link image',
            'toolbar' => 'undo bold italic styles link image',
        ]
    ])

'upload_images' => [
    'enabled' => true,
    'disk' => 's3', // or 'local', 'public'
    'folder' => 'uploads/tinymce',
    'max_size' => 2048, // KB
],
bash
php artisan vendor:publish --tag="filament-tinymce-config"
bash
php artisan vendor:publish --tag="filament-tinymce-assets"