It would be nice if we might plug into the ckeditor module using drupal's own hook system.

One thing I needed was to be able to insert a different stylesheet depending on the page that was being viewed. As the ckeditor module has control over the configuration of the list of CSS stylesheets that ckeditor is asked to load and this is stored in a relatively organized $profile variable, I decided to try to implement a hook. This patch also makes the css_path key of the $profile->settings array into an array instead of a comma-separated list. This patch should allow the following code:

function hook_ckeditor_profile_alter(&$profile, $profile_name, $element_id, $path)
{
  /* only hit the right type of textarea */
  if($element_id != 'edit-body')
    return;

  /* substitute our current URL with the one that yeilds CSS */
  $css_path = preg_replace(';^book/edit/;', '%h' . 'book/css/', $path);
  $profile->settings['css_path'][] = $css_path;
}

Comments and suggestions are welcome :-). I expect this to be useful for more than just CSS stylesheets, but I don't have the time to document the portions of $profile->settings that I'm not interested in. Also, the patch is not adequately tested, I need to get stuff set up so I can possibly back/forward port it as well.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ohnobinki’s picture

Oh, and what would be the best way for me to document the availability and use of hook_ckeditor_profile_alter()?

dczepierga’s picture

Status: Active » Closed (won't fix)

I think this is not needed for now, if we do sth like this we build API to manage all, but we will see in the near future. For now i closed this issue.

Greetings

ohnobinki’s picture

mkesicki’s picture

Status: Closed (won't fix) » Needs review