Install the Bundle Add the package via Composer:
composer require brandcodenl/n1ed-editor-bundle
Enable the bundle in config/bundles.php:
return [
// ...
BrandcodeNL\N1EDEditorBundle\BrandcodeNLN1EDEditorBundle::class => ['all' => true],
];
Configure the Bundle
Add the required configuration to .env:
N1ED_API_KEY=your_api_key_here
Define the bundle configuration in config/packages/brandcodenl_n1editor.yaml:
brandcode_nln1ed_editor:
includeEditor: true
apiKey: '%env(resolve:N1ED_API_KEY)%'
config:
framework: "bootstrap4"
ui:
iframePopUp: true
First Use Case: Basic Form Integration
Use the N1EDType in a Symfony form:
use BrandcodeNL\N1EDEditorBundle\Form\Type\N1EDType;
$builder->add('content', N1EDType::class, [
'label' => 'Rich Text Content',
'required' => false,
]);
Render the form in a Twig template:
{{ form_row(form.content) }}
Form Definition
Extend the N1EDType in your form builder for customization:
$builder->add('description', N1EDType::class, [
'config' => [
'ui' => [
'iframePopUp' => false,
'activateBootstrapEditorOnFullScreen' => true,
],
],
]);
Dynamic Configuration
Override bundle config per form or entity using pre_set_data or pre_bind:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$data = $event->getData();
$form = $event->getForm();
$form->add('content', N1EDType::class, [
'config' => $data->getEditorConfig() ?? [],
]);
});
}
Validation and Processing Handle submitted data in your controller:
public function saveAction(Request $request, YourEntity $entity)
{
$form = $this->createForm(YourFormType::class, $entity);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$content = $form->get('content')->getData(); // Raw HTML or JSON
// Process/save $content
}
}
Twig Integration Customize the editor rendering in Twig by extending the block:
{# templates/brandcodenl_n1editor/n1ed_widget.html.twig #}
{% block n1ed_widget %}
{{ parent() }}
<script>
// Custom JS logic for the editor
</script>
{% endblock %}
API Key Validation
N1ED_API_KEY on startup. Ensure the key is correct in .env or the editor will fail silently.CSS/JS Conflicts
includeCssToGlobalDoc: true is set, the bundle injects CSS globally. This may conflict with other front-end assets.includeCssToGlobalDoc: false and manually include build/app.css in your base template.Deprecated Configuration
rootContains: 'rows' option is undocumented and may break if N1ED updates its structure.Form Theme Overrides
templates/brandcodenl_n1editor/. Overriding these requires clearing the cache:
php bin/console cache:clear
Editor Initialization Race Conditions
includeEditor: true flag is set.apiKey is correctly resolved from .env.Enable Debug Mode
Set includeEditor: false in development to bypass the editor and test form submission:
brandcode_nln1ed_editor:
includeEditor: false # Debug mode
Log Submitted Data Dump the raw editor output in your controller to verify data structure:
dump($form->get('content')->getData());
Expected output: HTML string or JSON (depends on N1ED config).
Check Network Requests
https://n1ed.com/api/.Custom Editor Config Dynamically pass config per field:
$builder->add('bio', N1EDType::class, [
'config' => [
'ui' => [
'toolbar' => ['bold', 'italic', 'insertImage'], // Custom toolbar
],
],
]);
Event Listeners Attach listeners to the form for pre/post-processing:
$builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) {
$data = $event->getData();
// Sanitize or transform $data before submission
});
Asset Management Override the default CSS/JS paths in config:
brandcode_nln1ed_editor:
config:
include:
css:
- 'path/to/custom.css'
js:
- 'path/to/custom.js'
How can I help you explore Laravel packages today?