Fields

TinyMce

Inherits Textarea.

  • has the same capabilities

[!IMPORTANT] Before using this field, you must register on the Tiny.Cloud website, obtain a token, and add it to your .env.

TINYMCE_TOKEN="YOUR_TOKEN"

Installation

composer require moonshine/tinymce

Basics

use MoonShine\TinyMce\Fields\TinyMce;
 
TinyMce::make('Description')

Default Config

The TinyMce field by default uses the most commonly used settings, such as plugins, menubar, and toolbar.

To change the default settings, you need to publish the configuration file:

php artisan vendor:publish --tag="moonshine-tinymce-config"

You can also add additional parameters to the configuration file that will be applied to all TinyMce fields.

'options' => [
'forced_root_block' => 'div',
'force_br_newlines' => true,
'force_p_newlines' => false,
],

Locale

By default, the locale of your application is used, but you can specify a specific locale with the locale() method.

locale(string $locale)
TinyMce::make('Description')
->locale('ru');

Currently, English (en), Russian (ru), and Ukrainian (uk) are available, but we are always ready to add others.

If you want to add new localizations, create a task or submit a pull request.

Plugins

The plugins() method allows you to completely override the plugins that will be used by the field.

plugins(array $plugins)
TinyMce::make('Description')
->plugins(['code', 'image', 'link', 'media', 'table'])

The addPlugins() method allows you to add new plugins to the default plugins.

addPlugins(array $plugins)
TinyMce::make('Description')
->addPlugins(['wordcount'])

The removePlugins() method allows you to exclude plugins that will be used in the field.

removePlugins(array $plugins)
TinyMce::make('Description')
->removePlugins(['autoresize'])

The menubar() method allows you to completely override the menu bar for the field.

menubar(string|bool $menubar)
TinyMce::make('Description')
->menubar('file edit view')

Toolbar

The toolbar() method allows you to completely override the toolbar for the field.

toolbar(string|bool|array $toolbar)
TinyMce::make('Description')
->toolbar('file edit view')

Options

The addOption() method allows you to add additional parameters for the field.

addOption(string $name, string|int|float|bool|array $value)
TinyMce::make('Description')
->addOption('forced_root_block', 'div')

The addCallback() method allows you to add callback parameters for the field.

addCallback(string $name, string $value)
TinyMce::make('Description')
->addCallback('setup', '(editor) => console.log(editor)')

You can use strings, numbers, boolean values, and arrays as values.

File Manager

If you want to use the file manager in TinyMce, you need to install the Laravel FileManager package.

Installation

composer require unisharp/laravel-filemanager
 
php artisan vendor:publish --tag=lfm_config
php artisan vendor:publish --tag=lfm_public

Be sure to set the use_package_routes flag in the lfm configuration to false; otherwise, route caching will result in an error.

// config/lfm.php
 
'use_package_routes' => false,

Routing

Create a routes file, for example routes/moonshine.php, and register the LaravelFilemanager routes.

use Illuminate\Support\Facades\Route;
use UniSharp\LaravelFilemanager\Lfm;
 
Route::prefix('laravel-filemanager')->group(function () {
Lfm::routes();
});

RouteServiceProvider

Register the generated routes file in app/Providers/RouteServiceProvider.php.

The route file must be in the moonshine middleware group!

public function boot()
{
// ...
 
$this->routes(function () {
// ...
 
Route::middleware('moonshine')
->namespace($this->namespace)
->group(base_path('routes/moonshine.php'));
});
}

To restrict access to only users authenticated in the admin panel, you need to add the MoonShine\Laravel\Http\Middleware\Authenticate middleware.

use MoonShine\Laravel\Http\Middleware\Authenticate;
 
// ...
 
public function boot()
{
// ...
 
$this->routes(function () {
// ...
 
Route::middleware(['moonshine', Authenticate::class])
->namespace($this->namespace)
->group(base_path('routes/moonshine.php'));
});
}

Configuration

You need to add an option for the field.

TinyMce::make('Description')
->addOptions([
'file_manager' => 'laravel-filemanager',
])

or add it to the configuration file config/moonshine_tinymce.php so that it applies to all TinyMCe fields.

'options' => [
'file_manager' => 'laravel-filemanager',
],