diff --git a/editors/ckeditor.inc b/editors/ckeditor.inc
index 896fc84..05ee5ed 100644
--- a/editors/ckeditor.inc
+++ b/editors/ckeditor.inc
@@ -164,7 +164,7 @@ function wysiwyg_ckeditor_settings($editor, $config, $theme) {
// Versions below 3.0.1 could only handle one stylesheet.
if (version_compare($editor['installed version'], '3.0.1.4391', '<')) {
if ($config['css_setting'] == 'theme') {
- $settings['contentsCss'] = reset(wysiwyg_get_css());
+ $settings['contentsCss'] = reset(wysiwyg_get_css($config['css_theme']));
}
elseif ($config['css_setting'] == 'self' && isset($config['css_path'])) {
$settings['contentsCss'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme()));
@@ -172,7 +172,7 @@ function wysiwyg_ckeditor_settings($editor, $config, $theme) {
}
else {
if ($config['css_setting'] == 'theme') {
- $settings['contentsCss'] = wysiwyg_get_css();
+ $settings['contentsCss'] = wysiwyg_get_css($config['css_theme']);
}
elseif ($config['css_setting'] == 'self' && isset($config['css_path'])) {
$settings['contentsCss'] = explode(',', strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme())));
diff --git a/editors/fckeditor.inc b/editors/fckeditor.inc
index fba81f6..69bc627 100644
--- a/editors/fckeditor.inc
+++ b/editors/fckeditor.inc
@@ -129,7 +129,7 @@ function wysiwyg_fckeditor_settings($editor, $config, $theme) {
if (isset($config['css_setting'])) {
if ($config['css_setting'] == 'theme') {
- $settings['EditorAreaCSS'] = implode(',', wysiwyg_get_css());
+ $settings['EditorAreaCSS'] = implode(',', wysiwyg_get_css($config['css_theme']));
}
elseif ($config['css_setting'] == 'self' && isset($config['css_path'])) {
$settings['EditorAreaCSS'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme()));
diff --git a/editors/openwysiwyg.inc b/editors/openwysiwyg.inc
index 3a4b66c..e780b4e 100644
--- a/editors/openwysiwyg.inc
+++ b/editors/openwysiwyg.inc
@@ -100,7 +100,7 @@ function wysiwyg_openwysiwyg_settings($editor, $config, $theme) {
if (isset($config['css_setting'])) {
if ($config['css_setting'] == 'theme') {
- $settings['CSSFile'] = reset(wysiwyg_get_css());
+ $settings['CSSFile'] = reset(wysiwyg_get_css($config['css_theme']));
}
elseif ($config['css_setting'] == 'self' && isset($config['css_path'])) {
$settings['CSSFile'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme()));
diff --git a/editors/tinymce.inc b/editors/tinymce.inc
index b88f07f..998705b 100644
--- a/editors/tinymce.inc
+++ b/editors/tinymce.inc
@@ -188,7 +188,7 @@ function wysiwyg_tinymce_settings($editor, $config, $theme) {
if (isset($config['css_setting'])) {
if ($config['css_setting'] == 'theme') {
- $settings['content_css'] = implode(',', wysiwyg_get_css());
+ $settings['content_css'] = implode(',', wysiwyg_get_css($config['css_theme']));
}
elseif ($config['css_setting'] == 'self' && isset($config['css_path'])) {
$settings['content_css'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme()));
diff --git a/editors/wymeditor.inc b/editors/wymeditor.inc
index 042bc23..1765675 100644
--- a/editors/wymeditor.inc
+++ b/editors/wymeditor.inc
@@ -172,7 +172,7 @@ function wysiwyg_wymeditor_settings($editor, $config, $theme) {
if (isset($config['css_setting'])) {
if ($config['css_setting'] == 'theme') {
// WYMeditor only supports one CSS file currently.
- $settings['stylesheet'] = reset(wysiwyg_get_css());
+ $settings['stylesheet'] = reset(wysiwyg_get_css($config['css_theme']));
}
elseif ($config['css_setting'] == 'self' && isset($config['css_path'])) {
$settings['stylesheet'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme()));
diff --git a/editors/yui.inc b/editors/yui.inc
index 845a1af..67753ff 100644
--- a/editors/yui.inc
+++ b/editors/yui.inc
@@ -200,7 +200,7 @@ function wysiwyg_yui_settings($editor, $config, $theme) {
if (isset($config['css_setting'])) {
if ($config['css_setting'] == 'theme') {
- $settings['extracss'] = wysiwyg_get_css();
+ $settings['extracss'] = wysiwyg_get_css($config['css_theme']);
}
elseif ($config['css_setting'] == 'self' && isset($config['css_path'])) {
$settings['extracss'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme()));
diff --git a/wysiwyg.admin.inc b/wysiwyg.admin.inc
index ff23b28..df73c18 100644
--- a/wysiwyg.admin.inc
+++ b/wysiwyg.admin.inc
@@ -40,6 +40,7 @@ function wysiwyg_profile_form($form, &$form_state, $profile) {
'apply_source_formatting' => FALSE,
'paste_auto_cleanup_on_paste' => FALSE,
'css_setting' => 'theme',
+ 'css_theme' => variable_get('node_admin_theme') ? variable_get('admin_theme') : variable_get('theme_default'),
'css_path' => NULL,
'css_classes' => NULL,
);
@@ -270,7 +271,25 @@ function wysiwyg_profile_form($form, &$form_state, $profile) {
'#title' => t('Editor CSS'),
'#default_value' => $profile->settings['css_setting'],
'#options' => array('theme' => t('Use theme CSS'), 'self' => t('Define CSS'), 'none' => t('Editor default CSS')),
- '#description' => t('Defines the CSS to be used in the editor area.
Use theme CSS - loads stylesheets from current site theme.
Define CSS - enter path for stylesheet files below.
Editor default CSS - uses default stylesheets from editor.'),
+ '#description' => t('Defines the CSS to be used in the editor area.
Use theme CSS - loads stylesheets from the theme specified below.
Define CSS - enter path for stylesheet files below.
Editor default CSS - uses default stylesheets from editor.'),
+ );
+
+ $themes = list_themes();
+ $theme_list = array();
+ foreach ($themes as $theme) {
+ if ($theme->status) {
+ $theme_list[$theme->name] = $theme->info['name'];
+ }
+ }
+ $form['css']['css_theme'] = array(
+ '#type' => 'select',
+ '#title' => t('Theme'),
+ '#default_value' => $profile->settings['css_theme'],
+ '#description' => t("Select which theme's CSS to apply to the editor.
Note: This is only applied when 'Editor CSS' field above is set to 'Use theme CSS'"),
+ '#options' => $theme_list,
+ '#states' => array(
+ 'visible' => array('select[name="css_setting"]' => array('value' => 'theme')),
+ ),
);
$form['css']['css_path'] = array(
diff --git a/wysiwyg.install b/wysiwyg.install
index 038ba46..07fbe1a 100644
--- a/wysiwyg.install
+++ b/wysiwyg.install
@@ -310,3 +310,24 @@ function wysiwyg_update_7200() {
));
}
}
+
+/**
+ * Add config value to set editor theme, set default value for existing profiles.
+ */
+function wysiwyg_update_7201() {
+ $css_theme = variable_get('node_admin_theme') ? variable_get('admin_theme') : variable_get('theme_default');
+
+ $profiles = db_query('SELECT format, settings FROM {wysiwyg}');
+ foreach ($profiles as $profile) {
+ $profile->settings = unserialize($profile->settings);
+ $profile->settings['css_theme'] = $css_theme;
+ db_update('wysiwyg')
+ ->fields(array(
+ 'settings' => serialize($profile->settings),
+ ))
+ ->condition('format', $profile->format)
+ ->execute();
+ }
+
+ wysiwyg_profile_cache_clear();
+}
diff --git a/wysiwyg.module b/wysiwyg.module
index 31f3228..5e5e2e8 100644
--- a/wysiwyg.module
+++ b/wysiwyg.module
@@ -602,28 +602,46 @@ function wysiwyg_get_editor_config($profile, $theme) {
* This assumes that the content editing area only needs stylesheets defined
* for the scope 'theme'.
*
+ * @param $theme
+ * The theme to retrieve stylesheets for.
+ *
* @return
* An array containing CSS files, including proper base path.
*/
-function wysiwyg_get_css() {
+function wysiwyg_get_css($theme) {
static $files;
if (isset($files)) {
return $files;
}
- // In node form previews, the theme has not been initialized yet.
- if (!empty($_POST)) {
- drupal_theme_initialize();
- }
$files = array();
- foreach (drupal_add_css() as $filepath => $info) {
- if ($info['group'] >= CSS_THEME && $info['media'] != 'print') {
- if (file_exists($filepath)) {
- $files[] = base_path() . $filepath;
+ $stylesheets = array();
+ $themes = list_themes();
+ if (isset($themes[$theme]->info['base_theme'])) {
+ foreach ($themes[$themes[$theme]->info['base_theme']]->stylesheets as $media => $media_stylesheet) {
+ if ($media !== 'print') {
+ foreach ($media_stylesheet as $stylesheet) {
+ $stylesheets[] = $stylesheet;
+ }
+ }
+ }
+ }
+ if (isset($themes[$theme]->stylesheets)) {
+ foreach ($themes[$theme]->stylesheets as $media => $media_stylesheet) {
+ if ($media !== 'print') {
+ foreach ($media_stylesheet as $stylesheet) {
+ $stylesheets[] = $stylesheet;
+ }
}
}
}
+ foreach ($stylesheets as $path) {
+ if (file_exists($path)) {
+ $files[] = base_path() . $path;
+ }
+ }
+
return $files;
}