A Drupal module that provides EditorJS integration with inline editing capabilities for rich text content.
- EditorJS Integration: Full EditorJS editor support with configurable tools
- Inline Editing: Click-to-edit functionality on rendered EditorJS content
- AJAX Saving: Save changes without page refresh
- Reusable Components: Generic field templates and wrapper components
- CSRF Protection: Secure AJAX requests with CSRF token validation
- Responsive Design: Mobile-friendly editing interface
- Place the module in
web/modules/custom/editorjs_editor/ - Enable the module via Drupal admin or Drush:
ddev drush en editorjs_editor
- Clear cache:
ddev drush cache:rebuild
- Go to Configuration > Text formats and editors
- Create or edit a text format
- Select "EditorJS" as the text editor
- Configure available tools in the EditorJS settings
- Go to Structure > Content types > [Your Content Type] > Manage fields
- Add or edit a text field (Long text)
- Set the text format to use EditorJS
- Configure field display settings
The module automatically enables inline editing for EditorJS content:
- View Mode: Click on any EditorJS content to start editing
- Edit Mode: Use the EditorJS toolbar to modify content
- Save: Click the "Save" button to save changes
- Cancel: Click "Cancel" to discard changes
The module works with any text field using EditorJS format:
- Body fields (
field--node--body.html.twig) - Service descriptions (
field--field-service-description.html.twig) - Any text_long field (
field--text-long.html.twig)
editorjs_editor/
├── README.md # This file
├── editorjs_editor.info.yml # Module definition
├── editorjs_editor.module # Main module file with hooks
├── editorjs_editor.routing.yml # Route definitions
├── editorjs_editor.libraries.yml # Asset library definitions
├── editorjs_editor.services.yml # Service definitions
├── editorjs_editor.schema.yml # Configuration schema
├── drush.services.yml # Drush command definitions
├── css/
│ └── editorjs.css # EditorJS styling
├── js/
│ └── editorjs-inline.js # Inline editing JavaScript
└── src/
└── Controller/
└── InlineEditController.php # AJAX save endpoint
The module requires specific Twig templates in your theme:
field--text-long.html.twig- Generic template for text_long fieldseditorjs-field-wrapper.html.twig- Reusable wrapper component
Include the wrapper in your field templates:
{% include '@your_theme/field/editorjs-field-wrapper.html.twig' with {
'item': item,
'field_name': field_name,
'element': element
} %}- File:
editorjs_editor.module - Purpose: Processes EditorJS content and adds inline editing data
- Parameters:
$build,$entity,$display
- File:
editorjs_editor.module - Purpose: Attaches CSRF token for AJAX requests
- Parameters:
$attachments
- Method: POST
- Controller:
InlineEditController::save() - Purpose: Saves inline edited content via AJAX
- Access: Authenticated users (configurable)
- Purpose: Handles inline editing functionality
- Dependencies: Drupal, jQuery, once, drupalSettings
- Features:
- Click detection on EditorJS content
- EditorJS initialization
- AJAX save functionality
- Error handling and user feedback
-
Install EditorJS tool packages:
npm install @editorjs/tool-name
-
Update
editorjs_editor.libraries.yml:editorjs.core: js: js/editorjs-core.js: {} js/editorjs-tool-name.js: {}
-
Configure the tool in EditorJS settings
Customize the appearance by overriding CSS in your theme:
/* Override EditorJS styles */
.codex-editor {
/* Your custom styles */
}
/* Override inline editing styles */
[data-editorjs-content="true"] {
/* Your custom styles */
}Extend the inline editing functionality:
// In your theme's JavaScript
Drupal.behaviors.customEditorJS = {
attach: function (context, settings) {
// Your custom EditorJS enhancements
}
};-
Inline editing not appearing
- Check that the field template includes the wrapper component
- Verify EditorJS data is present in the render array
- Clear Drupal cache
-
JavaScript errors
- Check browser console for errors
- Verify all dependencies are loaded
- Check CSRF token is available
-
Save not working
- Verify user has edit permissions
- Check AJAX endpoint is accessible
- Verify CSRF token is valid
Enable debug logging in JavaScript:
// Add to editorjs-inline.js
const DEBUG = true;
if (DEBUG) {
console.log('Debug information:', data);
}- CSRF Protection: All AJAX requests include CSRF tokens
- Access Control: Inline editing requires appropriate permissions
- Input Validation: Content is validated before saving
- XSS Prevention: Output is properly escaped
- Asset Loading: CSS/JS are loaded only when needed
- Caching: EditorJS content is cached appropriately
- Lazy Loading: EditorJS tools are loaded on demand
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This module is licensed under the GPL-2.0+ license.
For issues and questions:
- Create an issue in the project repository
- Check the Drupal documentation
- Review the EditorJS documentation
- Initial release
- EditorJS integration
- Inline editing functionality
- AJAX save capability
- Reusable wrapper components
- CSRF protection
- Responsive design