I'd like to override a bunch of the CKEditor dataProcessor.writer rules, preferably in a transportable, without-patching-ckediter-3.0.js way. If I didn't care about doing things the Drupal way I would do something like:

CKEDITOR.editorConfig = function( config ) {
//... bunches of config
}

CKEDITOR.on( 'instanceReady', function( ev )
    {
        // Ends self closing tags the HTML4 way, like <br>.
        ev.editor.dataProcessor.writer.selfClosingEnd = '>';
    });

A good way to do this using the WYSIWYG API, I don't know. Looking through the code, it seems like wysiwyg_editor_settings_alter() adds keys and values inside CKEDITOR.editorConfig = function( config ) {}, but I need to add something after. Next thought was to try a custom plugin using hook_wysiwyg_plugin(), but I couldn't seem to get things working:

function mymodule_wysiwyg_plugin($editor, $version) {
  switch ($editor) {
    case 'ckeditor':
      return array(
        'cked_advanced_config' => array(
          'path' => drupal_get_path('module', 'mymodule'),
          'filename' => 'my-additional-config.js',
          'load' => TRUE,
          'internal' => FALSE,
        ),
      );
  }
}

Right now I have the .js kludged in there with drupal_add_js() that only fires if there's a CKEditor on the page, but I'm sure I'm missing something. Any pointers in the right direction?

Comments

RobW’s picture

Title: Set editor properties outside of what wysiwyg_editor_settings_alter() can change. » Setting editor properties that wysiwyg_editor_settings_alter() can't touch.
RobW’s picture

Issue summary: View changes

thought I had markdown. Marking up correctly.

RobW’s picture

Status: Active » Closed (fixed)

Ah, figured out an ok way to do it. The CKEditor docs on custom config files and this tutorial show that in the custom config.js we can specify another custom config file, and on and on forever. The last file specified takes precedence, and the settings cascade back.

So we can add something like

  $settings['customConfig'] = base_path() . drupal_get_path('module', 'mymodule') . '/my-additional-config.js';

to our hook_wysiwyg_editor_settings_alter(), and put all of the functions like CKEDITOR.on( 'instanceReady', function( ev ), CKEDITOR.on( 'dialogDefinition', function( ev ), and CKEDITOR.replace() in that new configuration .js.

We're still serving more js files to the page, but at least all of the settings are referenced in the same place, through a single settings array. If there's a better way, please let me know.

RobW’s picture

Issue summary: View changes

editing for consistancy