GeniXCMS

Editor Class

categoryAPI edit_calendar04 Apr 2026

Editor Class API

The Editor class is the central coordination point for WYSIWYG editor engines in GeniXCMS. It manages the registration of editor types and handles the conditional loading of CSS/JS assets based on the user's active editor preference.


Static Methods

init()

Bootstraps the editor system. This method is called during the core boot sequence. It:

  1. Registers the built-in editors (summernote, editorjs).
  2. Applies the editor_type_options filter to allow modules to add or modify editors.
  3. Detects the active editor from system options and executes its registration callback.
public static function init()

register()

Registers a new editor engine with the system.

public static function register(string $id, string $name, callable $callback)
  • $id: A unique slug for the editor (e.g., 'gxeditor', 'tinymce').
  • $name: The display name shown in selecting the editor in System Settings.
  • $callback: The function to execute if this editor is active. This callback should handle all Asset registration and enqueuing.

getEditors()

Retrieves a list of all registered editor engines.

public static function getEditors() : array
  • Returns: An associative array [id => name].

Internal Engine Callbacks

The Editor class contains built-in methods used as callbacks for core engines. These demonstrate how to use the Asset class for editor setup:

summernote()

The callback for the Summernote Classic editor. It:

  • Registers Summernote CSS/JS from CDN.
  • Injects a "raw" initialization script that handles bulk textarea activation and elFinder image uploads.

editorjs()

The callback for the Editor.js block editor. It:

  • Registers core Editor.js and various tool plugins (Header, List, Image, etc.).
  • Injects a complex "raw" handler that manages the conversion between block JSON and GeniXCMS compatible HTML during form submission.

Hooks

editor_type_options (Filter)

Filters the available editor list. Modules can add their own editors to this list or remove default ones.

Example:

Hooks::filter('editor_type_options', function($options) {
    $options['my_mod_editor'] = 'My Module Editor';
    return $options;
});

Example: Custom Editor Registration

To register a custom editor from a module:

// In MyModule::init()
Editor::register('my_editor', 'My Cool Editor', function() {
    // 1. Register assets
    Asset::register('my-editor-js', 'js', Site::$url . '/assets/js/my-editor.js');

    // 2. Enqueue assets
    Asset::enqueue('my-editor-js');

    // 3. Inject init script
    Asset::load('my-editor-init', 'raw', '<script>/* init logic */</script>');
});

See Also