benjaminlazarecki/scarepiceditor-bundle
Install via Composer
composer require benjaminlazarecki/scarepiceditor-bundle
Ensure the bundle is enabled in config/bundles.php:
return [
// ...
BenjaminLazarecki\ScarEpicEditorBundle\ScarEpicEditorBundle::class => ['all' => true],
];
Basic Form Integration
Register the epic_editor type in your form builder:
use BenjaminLazarecki\ScarEpicEditorBundle\Form\Type\EpicEditorType;
$builder->add('content', EpicEditorType::class);
First Use Case Render the editor in a Twig template:
{{ form_start(form) }}
{{ form_row(form.content) }}
<button type="submit">Save</button>
{{ form_end(form) }}
The editor will auto-initialize with default EpicEditor settings.
Dynamic Configuration Override default EpicEditor options via form options:
$builder->add('content', EpicEditorType::class, [
'options' => [
'editor_options' => [
'basePath' => '/path/to/epic-editor',
'toolbar' => ['bold', 'italic', 'image'],
],
],
]);
Asset Management
{{ encore_entry_link_tags('app') }} {# or manually include #}
<link rel="stylesheet" href="{{ asset('path/to/epic-editor/epiceditor.css') }}">
Form Handling
Reusable Components Create a base form type for common use cases:
class RichTextFormType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('body', EpicEditorType::class, [
'editor_options' => $options['editor_config'] ?? [],
]);
}
}
getConfig() method.Asset Paths
basePath). Use asset() in Twig or url() in PHP:
'basePath' => $this->container->get('router')->generate('asset', ['path' => 'path/to/epic-editor']),
basePath in config/packages/scare_epic_editor.yaml:
scare_epic_editor:
base_path: '%kernel.project_dir%/vendor/oscargodson/epiceditor'
CSRF Token Conflicts
config/packages/security.yaml:
enable_csrf: true
ignore_csrf: true # For AJAX-only forms (use cautiously)
Markdown Support
$builder->add('content', EpicEditorType::class, [
'editor_options' => ['outputFormat' => 'markdown'],
]);
marked.js).Form Theming
epic_editor_widget.html.twig template to customize the editor container:
{% block epic_editor_widget %}
<div class="custom-editor">
{{ parent() }}
</div>
{% endblock %}
dump($form->getData()) in your controller.scare_epic_editor.yaml settings with:
php bin/console debug:config scare_epic_editor
Custom Toolbars Extend the form type to add dynamic toolbars:
class CustomEpicEditorType extends EpicEditorType {
public function configureOptions(OptionsResolver $resolver) {
$resolver->setDefaults([
'editor_options' => [
'toolbar' => ['bold', 'custom_button'],
],
]);
}
}
Event Listeners Hook into form events to modify editor behavior:
$form->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$event->getForm()->add('content', EpicEditorType::class, [
'editor_options' => ['readOnly' => true], // Conditional config
]);
});
Asset Versioning Append a query string to EpicEditor assets to bypass cache:
<script src="{{ asset('path/to/epic-editor/epiceditor.js?v=' ~ '1.0') }}"></script>
How can I help you explore Laravel packages today?