Filament Forms TinyEditor

repository·2.x·Indexed 42 days ago

https://github.com/mohamedsabil83/filament-forms-tinyeditor

A TinyMCE editor integration for Laravel Filament that allows developers to use a rich text editor within Filament forms. Supports custom profiles, toolbars, image uploads via HasFileAttachments, and localization. Compatible with Filament 2.x (package 1.x) and 3.x (package 2.x). Note: This project is no longer actively maintained.

Tokens
2.9K
Snippets
14
Records
19
Agent score
51%

What's inside Filament Forms TinyEditor

  1. Overview of Filament Forms TinyEditor

    2.x

    Filament Forms TinyEditor is a package for Laravel Filament that integrates the TinyMCE Editor into Filament Forms. It can be used within Filament admin panels or as a standalone component for Filament Forms.

    WARNING

    Deprecation Notice: This project is no longer actively maintained. For an actively supported alternative, consider using amidesfahani/filament-tinyeditor.

  2. Configure custom editor profiles and toolbars

    2.x

    To create custom editor profiles with specific plugins and toolbars, follow these steps:

    1. Publish the configuration file:
      php artisan vendor:publish --tag="filament-forms-tinyeditor-config"
    2. Define your profiles in the published config file (e.g., config/filament-forms-tinyeditor.php). Each profile is an array containing plugins and toolbar keys:
      'simple' => [
          'plugins' => 'directionality emoticons link wordcount',
          'toolbar' => 'removeformat | bold italic | rtl ltr | link emoticons',
      ],
    3. Apply the profile to your component using the profile() method:
      TinyEditor::make('content')->profile('your-profile-name')
    php artisan vendor:publish --tag="filament-forms-tinyeditor-config"
  3. Upgrade from 1.x to 2.x

    2.x

    Version 2.x switched from a local TinyMCE installation to a CDN-based version. To upgrade successfully:

    1. Delete the old local files by removing the directory: public/vendor/filament-forms-tinyeditor.
    2. Upgrade the package via Composer.
    3. If using Forms standalone, run php artisan filament:assets to refresh assets.
    # 1. Remove old directory
    rm -rf public/vendor/filament-forms-tinyeditor
    
    # 2. Upgrade (via composer)
    composer require mohamedsabil83/filament-forms-tinyeditor
    
    # 3. Refresh assets (if using Forms standalone)
    php artisan filament:assets
  4. How TinyEditor profiles work

    2.x

    The TinyEditor component uses a profile system to manage complex configurations. When you call profile('name'), the component looks up settings in the filament-forms-tinyeditor.profiles.{name} configuration section.

    This profile determines:

    • Plugins: The list of TinyMCE plugins to load.
    • Toolbar: The string defining the toolbar buttons.
    • Custom Configs: Additional TinyMCE configuration options.
    • Upload Directory: The directory used for file attachments via getFileAttachmentsDirectory().

    If simple() is called, it overrides the profile's plugins and toolbar with a minimal set. If no profile is specified, it defaults to the default profile.

  5. Add custom TinyMCE configurations

    2.x

    You can inject arbitrary TinyMCE configuration options via the custom_configs key within a profile in your Laravel configuration file. Note that you must convert TinyMCE's JSON format into PHP arrays.

    Example of adding image_advtab to a profile:

    // config/filament-forms-tinyeditor.php
    
    'simple' => [
        'plugins' => 'directionality emoticons link wordcount',
        'toolbar' => 'removeformat | bold italic | rtl ltr | link emoticons',
        'custom_configs' => [
            'image_advtab' => true
        ]
    ],
  6. Configure the TinyEditor component

    2.x

    The TinyEditor component allows you to integrate the TinyMCE rich text editor into Filament forms. You can customize its appearance, functionality, and behavior using several fluent methods.

    Key Configuration Options

    • Simple Mode: Use simple() to enable a lightweight version of the editor with a reduced set of plugins and toolbar buttons.
    • Profiles: Use profile('name') to switch between predefined configuration profiles defined in your filament-forms-tinyeditor config file. This affects plugins, toolbar, and custom configs.
    • Toolbar & Menu: Use showMenuBar() to display the TinyMCE menu bar and toolbarSticky() to make the toolbar stick to the top.
    • Sizing: Control the editor height using minHeight(int) and maxHeight(int). You can also set previewMinHeight(int) and previewMaxHeight(int) for the preview mode.
    • Language: Set the editor language using language(string|\Closure). By default, it uses the application's current locale.
    • Templates: Use template(string) to apply a specific TinyMCE template defined in your configuration files.
    • Plugins: You can add additional plugins via setExternalPlugins(array $plugins).

    URL Handling

    • documentBaseUrl(string $url): Sets the base URL for documents.
    • relativeUrls(bool $value): Determines if URLs should be relative.
    • convertUrls(bool $value): Determines if URLs should be converted.
    use Mohamedsabil83\FilamentFormsTinyeditor\Components\TinyEditor;
    
    TinyEditor::make('content')
        ->simple()
        ->minHeight(300)
        ->maxHeight(600)
        ->toolbarSticky()
        ->profile('custom_profile')
        ->language('fr')