ezsystems/ezplatform-richtext
eZ Platform RichText adds RichText field support to eZ Platform, handling storage and rendering of rich content with XML-based markup, transformations, and editor integration. Use it to manage formatted text, embeds, and structured content in your CMS.
Installation
Add the bundle to your Laravel project via Composer (if adapted for Laravel via a bridge like ezsystems/ezplatform-laravel-bridge):
composer require ezsystems/ezplatform-richtext
Register the bundle in config/app.php under providers (if using a Laravel bridge).
Configuration Publish the default configuration:
php artisan vendor:publish --provider="EzSystems\EzPlatformRichText\EzPlatformRichTextBundle" --tag="config"
Update config/ezplatform/richtext.yaml to define your rich text field types and toolbar configurations.
Basic Field Definition Define a rich text field in your content type (e.g., in a migration or content type service):
# Example in a content type YAML (adapted for Laravel)
fields:
body:
type: ezrichtext
toolbar: full
First Usage in a Controller
Inject the RichTextService and use it to render or process rich text:
use EzSystems\EzPlatformRichText\API\RichTextService;
public function show(RichTextService $richTextService, $contentId) {
$content = $contentService->load($contentId);
$richText = $content->getField('body')->value;
$html = $richTextService->convertToHTML($richText);
return view('content.show', ['html' => $html]);
}
Toolbar Setup
Define toolbars in config/ezplatform/richtext.yaml:
toolbars:
full:
groups:
- basic
- text
- lists
- links
Content Creation/Editing
RichTextService to validate and process rich text input from forms:
$richTextInput = $request->input('body');
$validated = $richTextService->validate($richTextInput, 'full');
$content->setFieldValue('body', $validated);
FormRequest:
public function rules()
{
return [
'body' => ['required', 'richtext:full'], // Custom validation rule
];
}
API/Headless CMS
$data = [
'title' => $content->getTitle(),
'body' => $richTextService->convertToArray($content->getField('body')->value),
];
return response()->json($data);
$richTextInput = $request->input('body');
$processed = $richTextService->convertFromArray($richTextInput);
Embedding in Blade Templates
{!! $richTextService->convertToHTML($content->body) !!}
richtext/editor.blade.php).Laravel Form Integration
collective/html or Laravel's built-in form helpers with the rich text editor:
{!! Form::textarea('body', old('body'), ['class' => 'richtext-editor']) !!}
ezrichtext bundle assets).Event Listeners
public function handle(ContentUpdateEvent $event)
{
$richText = $event->getContent()->getField('body')->value;
$richTextService->sanitize($richText);
}
Custom Field Types
use EzSystems\EzPlatformRichText\FieldType\RichTextType;
class CustomRichTextType extends RichTextType {
public function getSettings() {
return array_merge(parent::getSettings(), ['custom' => true]);
}
}
Asset Management
config/ezplatform/richtext.yaml:
uploads:
directory: public/uploads/richtext
url: /uploads/richtext
Toolbar Misconfiguration
basic, text) exist in the toolbar definition. Validate YAML syntax for typos or missing colons.HTML Injection Risks
$richTextService->convertToHTML() with sanitization enabled:
$html = $richTextService->convertToHTML($richText, ['sanitize' => true]);
Database Storage
->with() to eager-load related content:
$content = Content::with('body')->find($id);
Editor Asset Conflicts
ezrichtext assets in a blade layout or use Laravel Mix to isolate dependencies:
@vite(['resources/js/ezrichtext.js'])
Laravel Caching Quirks
$cacheKey = "richtext_{$contentId}";
$html = Cache::remember($cacheKey, now()->addHours(1), function() use ($richTextService, $content) {
return $richTextService->convertToHTML($content->body);
});
Validation Errors
config/ezplatform/richtext.yaml:
debug: true
Editor Not Loading
php artisan vendor:publish --tag=ezrichtext-assets
Content Not Rendering
fields:
body:
type: ezrichtext
toolbar: full
Custom Sanitization
use EzSystems\EzPlatformRichText\API\Sanitizer\SanitizerInterface;
class CustomSanitizer implements SanitizerInterface {
public function sanitize($richText) {
// Custom logic
return $richText;
}
}
$app->bind(SanitizerInterface::class, CustomSanitizer::class);
Toolbar Plugins
toolbars:
custom:
groups:
- basic
items:
- name: customButton
icon: icon-custom
command: customCommand
tinymce.PluginManager.add('customCommand', function(editor) {
editor.addButton('customButton', {
text: 'Custom',
onclick: function() { /* ... */ }
});
});
Field Value Processing
$content->setFieldValue('body', $richTextService->processForStorage($richTextInput));
$storedRichText = $richTextService->processFromStorage($content->getField('body')->value);
Event Subscribers
RichTextConvertEvent):
public function onRichTextConvert(RichTextConvertEvent $event) {
if ($event->getType() === 'to_html') {
$event->setHtml($this->modifyHtml($event->getHtml()));
}
}
How can I help you explore Laravel packages today?