You are here

function wysiwyg_wymeditor_settings in Wysiwyg 7.2

Same name and namespace in other branches
  1. 5.2 editors/wymeditor.inc \wysiwyg_wymeditor_settings()
  2. 6.2 editors/wymeditor.inc \wysiwyg_wymeditor_settings()

Return runtime editor settings for a given wysiwyg profile.

Parameters

$editor: A processed hook_editor() array of editor properties.

$config: An array containing wysiwyg editor profile settings.

$theme: The name of a theme/GUI/skin to use.

Return value

A settings array to be populated in Drupal.settings.wysiwyg.configs.{editor}

1 string reference to 'wysiwyg_wymeditor_settings'
wysiwyg_wymeditor_editor in editors/wymeditor.inc
Plugin implementation of hook_editor().

File

editors/wymeditor.inc, line 129
Editor integration functions for WYMeditor.

Code

function wysiwyg_wymeditor_settings($editor, $config, $theme) {

  // @todo Setup $library in wysiwyg_load_editor() already.
  $library = isset($editor['library']) ? $editor['library'] : key($editor['libraries']);
  $settings = array(
    'basePath' => base_path() . $editor['library path'] . '/',
    'wymPath' => $editor['libraries'][$library]['files'][0],
    // WYMeditor's update event handler will revert the field contents if
    // changes were made after it was detached. Wysiwyg takes care of submit
    // events anyway so make sure WYMeditor does not bind it anywhere.
    'updateSelector' => '#wysiwyg-no-element',
    'updateEvent' => 'wysiwyg-no-event',
    'skin' => $theme,
  );
  if (version_compare($editor['installed version'], '1.0.0-b5', '>=')) {
    drupal_add_css($editor['library path'] . '/skins/' . $settings['skin'] . '/skin.css');
  }
  else {

    // @todo Does not work in Drupal; jQuery can live anywhere.
    $settings['jQueryPath'] = base_path() . 'misc/jquery.js';
  }
  if (isset($config['language'])) {
    $settings['lang'] = $config['language'];
  }

  // Add configured buttons.
  $settings['toolsItems'] = array();
  if (!empty($config['buttons'])) {
    $buttoninfo = _wysiwyg_wymeditor_button_info($editor['installed version']);
    $plugins = wysiwyg_get_plugins($editor['name']);
    foreach ($config['buttons'] as $plugin => $buttons) {
      foreach ($buttons as $button => $enabled) {

        // Iterate separately over buttons and extensions properties.
        foreach (array(
          'buttons',
          'extensions',
        ) as $type) {

          // Skip unavailable plugins.
          if (!isset($plugins[$plugin][$type][$button])) {
            continue;
          }

          // Add buttons.
          if ($type == 'buttons') {

            // Merge meta-data for internal default buttons.
            if (isset($buttoninfo[$button])) {
              $buttoninfo[$button] += array(
                'name' => $button,
              );
              $settings['toolsItems'][] = $buttoninfo[$button];
            }
            else {
              $settings['toolsItems'][] = array(
                'name' => $button,
                'title' => $plugins[$plugin][$type][$button],
                'css' => 'wym_tools_' . $button,
              );
            }
          }
        }
      }
    }
  }
  if (!empty($config['block_formats'])) {
    $containers = array(
      'p' => 'Paragraph',
      'h1' => 'Heading_1',
      'h2' => 'Heading_2',
      'h3' => 'Heading_3',
      'h4' => 'Heading_4',
      'h5' => 'Heading_5',
      'h6' => 'Heading_6',
      'pre' => 'Preformatted',
      'blockquote' => 'Blockquote',
      'th' => 'Table_Header',
    );
    foreach (explode(',', preg_replace('@\\s+@', '', $config['block_formats'])) as $tag) {
      if (isset($containers[$tag])) {
        $settings['containersItems'][] = array(
          'name' => strtoupper($tag),
          'title' => $containers[$tag],
          'css' => 'wym_containers_' . $tag,
        );
      }
    }
  }

  // Add editor content stylesheet.
  if (isset($config['css_setting'])) {
    if ($config['css_setting'] == 'theme') {

      // WYMeditor only supports one CSS file currently.
      $css = wysiwyg_get_css(isset($config['css_theme']) ? $config['css_theme'] : '');
      $settings['stylesheet'] = reset($css);
    }
    elseif ($config['css_setting'] == 'self' && isset($config['css_path'])) {
      $settings['stylesheet'] = strtr($config['css_path'], array(
        '%b' => base_path(),
        '%t' => drupal_get_path('theme', variable_get('theme_default', NULL)),
        '%q' => variable_get('css_js_query_string', ''),
      ));
    }
  }
  return $settings;
}