I was wondering if there was any way of adding in support for module included CSS files (or a good reason why it hasn't been included). I've noticed that it's easier to make a module that helps standardize page elements across multiple sites and wanted to be able to view what the page looks like in the text editor. I was able to add the following to wysiwyg_get_css in order to make it work, just wondering if there's a reason not to include this or at least allow for the option in addition to the 'theme' option of CSS to include.

function wysiwyg_get_css() {
  static $files;

  if (isset($files)) {
    return $files;
  }
  // In node form previews, the theme has not been initialized yet.
  init_theme();

  $files = array();
  
  foreach (drupal_add_css() as $media => $css) {
    if ($media != 'print') {
      foreach ($css['theme'] as $filepath => $preprocess) {
        if (file_exists($filepath)) {
          $files[] = base_path() . $filepath;
        }
      }
	  foreach ($css['module'] as $filepath => $preprocess) {
        if (file_exists($filepath)) {
          $files[] = base_path() . $filepath;
        }
      }
    }
  }
  return $files;
}

Comments

TwoD’s picture

If we include "module" stylesheets in the editor we'll get all kinds of files in there that we don't need, like admin_menu.css, content-module.css, views.css, img_assist.css, date.css, filefield.css - depending on which modules you have installed of course. Not to mention that all editor specific theme tweaks added by Wysiwyg will be included in the editing area for and from every included editor on the page.
Each of these also add another HTTP request each time an editor is attached (which hopefully results in a cache hit, but it's still more than what's really needed).

If your module adds stylesheets meant to influence the theme, why not use the second parameter to drupal_add_css('file.css', 'theme') (if you're on D6, on D7 use the 'type' => CSS_THEME property)?

btopro’s picture

Priority: Normal » Minor

I'll add the theme thing into my module, just seems like you could still want date, filefield or some others in addition to theme. Is there a way to say use theme css files and also include these entered via text field?

TwoD’s picture

Well, since we can't know which files a module will include, nor which files the user would like to keep in there, we can't build a black/white-list to filter the "module" stylesheets by automatically.

You should be able to include any stylesheet(s) by using the Define CSS option and the CSS path field. You'll have to include those from the theme too if that's what you want. Once again, we can't guess which files the user would like to keep in there so best to start with none.

If you need to override a lot of your regular style rules to get things to look nice in the editor, you might want to consider creating a file specifically for the editor and only include that one. Tweaks to your theme's stylesheets may have to be synced with the extra file, but you won't risk having in-editor tweaks ruining your theme outside the editor.

btopro’s picture

Status: Active » Closed (works as designed)

cool, thanks for explaining the rationale behind this