My goal was the next: I'm using the module less. This creates a new path in file system, and makes own css files. I thought, why can't define only path, if use settings "Define css" in Editor CSS field, and could load all css file within this path.

This patch makes a new placeholder %f to filesystem. If not .css file set, try to load .css files in directory. You can define '%f/css', if you want use the aggregated css files, or using modules less the correct path is: "%f/%t/[css_path_in_your_theme]". If css file couldn't loaded, set an error message.
I try to make this all of editors, where this settings enabled, but couldn't test it now. When I checked coder, it tells some minor bug, these are corrected too.

This is the base code for tinymce:

  if (isset($config['css_setting'])) {
    if ($config['css_setting'] == 'theme') {
      $settings['content_css'] = implode(',', wysiwyg_get_css());
    }
    elseif ($config['css_setting'] == 'self' && isset($config['css_path'])) {
      $csspath = strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme(), '%f' => file_directory_path()));
      if (preg_match('/.*\.css$/', $csspath)) {
        $settings['content_css'] = $csspath;
      }
      else {
        global $base_url;
        $cssfiles = file_scan_directory($csspath, '.*\.css$');
        if ($cssfiles) {
          foreach ($cssfiles as $key) {
            $filesarray[] = $base_url . '/' . $key->filename;
          }
        $settings['content_css'] = implode(',', $filesarray);
        }
        else {
          if (user_access('administer filters')) {
            drupal_set_message(t("The wysiwyg css path is not configured properly. Check the !settings_url settings page!", array('!settings_url' => l(t('Wysiwyg profiles'), 'admin/settings/wysiwyg'))), 'error');
          }
        }
      }
    }
  }

Comments

szantog’s picture

StatusFileSize
new18.64 KB

a small correction in patch

twod’s picture

Status: Needs review » Needs work

Thanks for the patch and cleanups, but let's keep coding style cleanups in separate patches to keep focus on the real changes.

I like the idea of fetching all .css files in a folder, but when implemented this way it means we have a folder scan on each page load where the editor appears. If there are more than one editor type loaded, that folder scan will also happen several times.
(The results from this function are not cached.)

Btw, you've got an extra .project file in the patch. ;)

szantog’s picture

StatusFileSize
new3.15 KB

Ok, this is now without cleanup. :)
In new patch I put the main function in .module, and cached the results. Now, I'm using it only in tinymce. If you think, this is the good way, I will apply it the into the other editors.

szantog’s picture

Status: Needs work » Needs review

and needs review..

sun’s picture

Title: Able to add custom *path* in "Define css" section » Add %f token for files directory in "Define CSS" setting
Status: Needs review » Needs work

We can add %f, but please only add it to the existing replacements, without the helper function. Make sure to add it in all editor support includes that contain the replacement code currently.

joelstein’s picture

Version: 6.x-2.x-dev » 7.x-2.x-dev
Status: Needs work » Needs review
StatusFileSize
new7.9 KB

Here's a patch for D7 which adds support for the %f token and adds help text everywhere it should appear.

jurriaanroelofs’s picture

Works great for me, +1
Allthough it hurts to see the same code repeated 10 time, maybe it could be refactored a little?