contao-components/tinymce4
TinyMCE 4 integration for Contao CMS. Provides a ready-to-use editor component and configuration suited to Contao back end usage, helping you embed and manage the TinyMCE WYSIWYG editor in your Contao installation.
Installation
composer require contao-components/tinymce4
Ensure your composer.json includes "minimum-stability": "dev" if using development versions.
Basic Setup
Add the TinyMCE service provider and alias in config/app.php:
'providers' => [
// ...
ContaoComponents\TinyMCE4\TinyMCEServiceProvider::class,
],
'aliases' => [
// ...
'TinyMCE' => ContaoComponents\TinyMCE4\Facades\TinyMCE::class,
],
First Use Case: Blade Integration In a Blade template, initialize TinyMCE with default settings:
{!! TinyMCE::script() !!}
<textarea id="my-editor"></textarea>
<script>
tinymce.init({
selector: '#my-editor',
plugins: 'advlist autolink lists link image charmap print preview',
toolbar: 'undo redo | bold italic | alignleft aligncenter alignright'
});
</script>
Dynamic Configuration Pass custom settings via Laravel’s config or a service container:
// config/tinymce.php
return [
'default' => [
'plugins' => 'code table',
'toolbar' => 'bold italic | code table',
],
];
Use in Blade:
{!! TinyMCE::script(config('tinymce.default')) !!}
Form Integration (Laravel Collective)
Attach TinyMCE to a {!! Form::textarea() !!} field:
{!! Form::textarea('content', old('content'), ['class' => 'tinymce-editor']) !!}
<script>
tinymce.init({ selector: '.tinymce-editor', ... });
</script>
Asset Optimization Use Laravel Mix/Vite to bundle TinyMCE plugins:
// resources/js/app.js
import 'tinymce/tinymce';
import 'tinymce/plugins/advlist';
tinymce.init({ ... });
Backend Admin Panels (Contao/Laravel Admin) Integrate with Contao’s DCA (Data Container) or Laravel Nova:
// Example: Contao DCA field config
$GLOBALS['TL_DCA']['tl_content']['fields']['text'] = [
'inputType' => 'textarea',
'eval' => ['tinymce' => ['plugins' => 'fullscreen']],
];
Asset Conflicts
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
{!! TinyMCE::script() !!}
@stack or mix-manifest to manage dependencies.CSRF Token Issues TinyMCE’s AJAX features (e.g., image uploads) may fail without CSRF meta tags:
<meta name="csrf-token" content="{{ csrf_token() }}">
Configure TinyMCE’s images_upload_url to include the token:
images_upload_url: '/upload?X-CSRF-TOKEN={{ csrf_token() }}',
Plugin Loading Order
image or link must be declared before they’re used in toolbar.tinymce is not defined errors (missing TinyMCE::script()).Laravel Mix/Vite Compatibility
tinymce is exposed:
// vite.config.js
export default {
define: {
global: 'window',
},
};
tinymce.init({ ... }).then(() => console.log('Initialized')); to verify setup./js/tinymce/tinymce.min.js).php artisan cache:clear and php artisan view:clear if configs aren’t updating.Custom Plugins Load plugins from a CDN or local path:
external_plugins: {
'my-plugin': '/vendor/tinymce/plugins/my-plugin/plugin.min.js'
},
Laravel Events
Trigger TinyMCE initialization via Laravel events (e.g., view.rendered):
// app/Providers/AppServiceProvider.php
view()->composer('*', function ($view) {
if ($view->getName() === 'editor') {
$view->with('tinymceConfig', config('tinymce.admin'));
}
});
Contao Hooks
Extend TinyMCE settings via Contao’s insertTag hook:
$GLOBALS['TL_HOOKS']['insertTag'][] = function ($tag) {
if ($tag['name'] === 'tinymce') {
$tag['attributes']['data-plugins'] = 'fullscreen';
}
return $tag;
};
Storage Integration For file uploads, create a Laravel route:
Route::post('/upload', [TinyMCEController::class, 'upload'])->middleware('auth');
// TinyMCEController.php
public function upload(Request $request) {
$file = $request->file('file');
$path = $file->store('tinymce');
return response()->json(['location' => $path]);
}
How can I help you explore Laravel packages today?