In FCKEditor I could use classes instead of just inserting style directly into the html. The way to do this (and a million other things) was to edit fckeditor.config.js. Is there something similar for CKEditor planned (see this for instance http://drupal.ckeditor.com/troubleshooting#7)?
I tried creating a module to add some javascript - something like this:

function mymodule_wysiwyg_editor_settings_alter(&$settings, &$context) {
  if($context['profile']->editor == 'ckeditor') {
    $settings['config.justifyClasses'] = "rteleft, rtecenter, rteright, rtejustify";
}

That didn't work.

I also tried just hacking directly like this:

function mymodule_init() {
   drupal_add_js('CKEDITOR.config.customConfig = \'' 
     . drupal_get_path('module', 'mymodule') 
     . '/ckeditor.config.js\';', 'inline');
}

That didn't work either. I think because it gets loaded after the CKEditor.

Any ideas, help appreciated.

Comments

twod’s picture

Status: Active » Closed (duplicate)

Try

function mymodule_wysiwyg_editor_settings_alter(&$settings, &$context) {
  if($context['profile']->editor == 'ckeditor') {
    $settings['justifyClasses'] = array('rteleft', 'rtecenter', 'rteright', 'rtejustify');
}

Everything in $settings is transfered to the instance's editor.config object after being converted from PHP objects/arrays to JavaScript Objects/Arrays (via drupal_add_js()). This allows us to change any setting which accepts JavaScript Booleans, Strings, Objects/Arrays and Numbers (or any combination of those) as values by using the PHP equivalents.

Modifying CKEditor's original configuration files will only have an effect if the changed setting is not being overridden by the settings sent from the server, which are set directly on the instance object (it's those which the _alter hook modifies). We don't officially support any modifications to the library files because we want as much as possible to be configurable via the GUI, and upgrading a lib is much easier when all its files are untouched. Fixing #313497: Allow configuration of advanced editor settings should mean manually editing files to change settings like this one is no longer needed, so marking as duplicate of that issue.

miiimooo’s picture

Thanks!

gooddesignusa’s picture

I'm trying to do something very similar. I want to use br's instead of p's when the user hits return. I tried making a module with this

<?php
function custom_code_wysiwyg_editor_settings_alter(&$settings, &$context) {
  if($context['profile']->editor == 'ckeditor') {
	$settings['enterMode'] = 'CKEDITOR.ENTER_BR';  
  }
}

http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.ente...

TwoD can you point me in the right direction.

edit:
Using these worked so i'm wonder if its something to do with enterMode. Also does it need to have a = instead of a : inside the JS settings.
not sure how it passes the settings to ckeditor.

    $settings['pasteFromWordRemoveFontStyles'] = 'true';
    $settings['pasteFromWordRemoveStyles'] = 'true';
    $settings['forcePasteAsPlainText'] = 'true';
    $settings['pasteFromWordPromptCleanup'] = 'false';
twod’s picture

CKEDITOR.ENTER_BR is a "constant" (just a globally defined variable in JavaScript), and PHP has no way to know what the actual value of that constant is. The code you have sets the value of enterMode to a String containing "CKEDITOR.ENTER_BR", which is meaningless to the editor.

Technically, so are the values "true" and "false" as they are both Strings and will both evaluate to the Boolean value true if used in a comparison.
You should use the PHP TRUE and FALSE values (without quotes), as drupal_add_js() knows to output these as the JS Booleans true and false.

In the case of CKEDITOR.ENTER_BR, you need to look up the actual value that constant is defined as and use that directly. The value can be found in ckeditor/_source/core/config.js line 12, and it appears to be 2.
So, this should do the trick:

function custom_code_wysiwyg_editor_settings_alter(&$settings, &$context) {
  if($context['profile']->editor == 'ckeditor') {
$settings['enterMode'] = 2; 
  }
}
robbertnl’s picture

I think i will use #3 and #4 together. Is this still the best solution by making a module for these settings only?

twod’s picture