You are here

function panopoly_wysiwyg_alter_wysiwyg_editor_settings in Panopoly WYSIWYG 7

Modify the WYSIWYG editor settings for Panopoly improvements.

This is meant to be called from hook_wysiwyg_editor_settings_alter().

Panopoly will call it on all of it's formats (those starting with 'panopoly_*'), however, you can use it to apply Panopoly's customizations to your formats as well!

For TinyMCE: this will change the editor skin, re-arrange the buttons, configure dialogs, and extend allowed markup for the Media module.

For Markitup: it'll add additional styles and configure headers and lists.

Parameters

$settings: An associative array of JavaScript settings to pass to the editor.

$context: An associative array containing additional context information:

  • editor: The plugin definition array of the editor.
  • profile: The editor profile object, as loaded from the database.
  • theme: The name of the editor theme/skin.

See also

hook_wysiwyg_editor_settings_alter().

1 call to panopoly_wysiwyg_alter_wysiwyg_editor_settings()
panopoly_wysiwyg_wysiwyg_editor_settings_alter in ./panopoly_wysiwyg.module
Implementation of hook_wysiwyg_editor_settings_alter()

File

./panopoly_wysiwyg.module, line 148

Code

function panopoly_wysiwyg_alter_wysiwyg_editor_settings(&$settings, $context) {
  switch ($context['editor']['name']) {
    case 'tinymce':

      // Define the skin to use
      $settings['skin'] = 'cirkuit';

      // Define the spellchecking settings
      $settings['spellchecker_languages'] = '+English=en';

      // BUTTON ORDER
      // If the user has set a custom button order with the WYSIWYG Button Order module, we'll use those.
      // We test for the presence of a button_order array element rather than using module_exists()
      // so that the user can also hardcode an order with hook_wysiwyg_editor_settings
      if (isset($context['profile']->settings['buttonorder'])) {
        $default_buttons = preg_replace('/separator,separator/', 'PAGEBREAK', $context['profile']->settings['buttonorder']);
      }
      else {
        $enabled_buttons = preg_split('/,/', $settings['theme_advanced_buttons1']);
        $default_buttons = array(
          'bold',
          'italic',
          'strikethrough',
          '|',
          'bullist',
          'numlist',
          'blockquote',
          '|',
          'justifyleft',
          'justifycenter',
          'justifyright',
          '|',
          'linkit',
          'unlink',
          'drupal_break',
          '|',
          'fullscreen',
          'spellchecker',
          'drupal_media',
          'captionfilter',
          'pdw_toggle',
          'PAGEBREAK',
          'formatselect',
          '|',
          'underline',
          '|',
          'justifyfull',
          '|',
          'forecolor',
          '|',
          'pastetext',
          'pasteword',
          'removeformat',
          '|',
          'charmap',
          '|',
          'outdent',
          'indent',
          '|',
          'undo',
          'redo',
        );
        foreach ($default_buttons as $button) {
          if (in_array($button, $enabled_buttons)) {
            unset($enabled_buttons[array_search($button, $enabled_buttons)]);
          }
          elseif ($button != '|' && $button != 'PAGEBREAK') {
            unset($default_buttons[array_search($button, $default_buttons)]);
          }
        }

        // If there are still any enabled buttons left, let's add them to the third row of buttons
        if (count($enabled_buttons) > 0) {
          $default_buttons[] = 'PAGEBREAK';
          $default_buttons = array_merge($default_buttons, $enabled_buttons);
        }
        $default_buttons = implode(',', $default_buttons);
      }

      // Define the final button row settings.
      $default_buttons_list = preg_split('/,PAGEBREAK,/', $default_buttons);
      $rows_count = count($default_buttons_list);
      for ($i = 0; $i < $rows_count; $i++) {
        $settings['theme_advanced_buttons' . ($i + 1)] = !empty($default_buttons_list[$i]) ? $default_buttons_list[$i] : NULL;
      }

      // Define PDW Plugin Settings
      $settings['pdw_toggle_on'] = '1';
      $settings['pdw_toggle_toolbars'] = $rows_count > 1 ? implode(',', range(2, $rows_count)) : '2';

      // Enable the inlinepopups and modal settings
      $settings['plugins'] .= ',inlinepopups';
      $settings['dialog_type'] = 'modal';

      // Allow extra elements for Media module
      // See - http://drupal.org/node/1835826
      if (empty($settings['extended_valid_elements'])) {
        $settings['extended_valid_elements'] = 'img[!src|title|alt|style|width|height|class|hspace|vspace|view_mode|format|fid]';
      }
      else {
        $settings['extended_valid_elements'] = array_merge(explode(',', $settings['extended_valid_elements']), array(
          'img[!src|title|alt|style|width|height|class|hspace|vspace|view_mode|format|fid]',
        ));

        // When adding new elements to $settings['extended_valid_elements'], make sure
        // that we're merging, and not overwriting.
        $settings_array = array();
        foreach ($settings['extended_valid_elements'] as $tag) {
          if (strpos("[", $tag) !== FALSE) {
            list($tag, $allowed_attributes) = explode('[', $tag);
            $allowed_attributes = explode('|', trim($allowed_attributes, ']'));
            foreach ($allowed_attributes as $key => $attribute) {
              $settings_array[$tag][$attribute] = $attribute;
            }
          }
        }
        $valid_elements = array();
        foreach ($settings_array as $tag => $allowed_attributes) {
          $attributes = in_array('*', $allowed_attributes) ? '*' : implode('|', $allowed_attributes);
          $valid_elements[] = $tag . '[' . $attributes . ']';
        }
        $settings['extended_valid_elements'] = implode(',', $valid_elements);
      }
      break;
    case 'markitup':

      // Load the appropriate CSS and JS
      drupal_add_css($context['editor']['library path'] . '/markitup/sets/html/style.css');
      drupal_add_js($context['editor']['library path'] . '/markitup/sets/html/set.js');

      // Define the new header buttons
      $header_buttons = array(
        'header-begin' => array(
          'className' => 'markItUpSeparator',
        ),
        'h1' => array(
          'name' => t('Heading 1'),
          'className' => 'markitup-h1',
          'key' => '1',
          'openWith' => '<h1(!( class="[![Class]!]")!)>',
          'closeWith' => '</h1>',
          'placeHolder' => 'Your title here...',
        ),
        'h2' => array(
          'name' => t('Heading 2'),
          'className' => 'markitup-h2',
          'key' => '2',
          'openWith' => '<h2(!( class="[![Class]!]")!)>',
          'closeWith' => '</h2>',
          'placeHolder' => 'Your title here...',
        ),
        'h3' => array(
          'name' => t('Heading 3'),
          'className' => 'markitup-h3',
          'key' => '3',
          'openWith' => '<h3(!( class="[![Class]!]")!)>',
          'closeWith' => '</h3>',
          'placeHolder' => 'Your title here...',
        ),
        'h4' => array(
          'name' => t('Heading 4'),
          'className' => 'markitup-h4',
          'key' => '4',
          'openWith' => '<h4(!( class="[![Class]!]")!)>',
          'closeWith' => '</h4>',
          'placeHolder' => 'Your title here...',
        ),
        'paragraph' => array(
          'name' => t('Paragraph'),
          'className' => 'markitup-paragraph',
          'key' => 'p',
          'openWith' => '<p(!( class="[![Class]!]")!)>',
          'closeWith' => '</p>',
        ),
        'header-end' => array(
          'className' => 'markItUpSeparator',
        ),
      );

      // Define the list styles
      $list_styles = array(
        'list-bullet' => array(
          'name' => t('Unordered List'),
          'className' => 'markitup-list-bullet',
          'openWith' => "<ul>\n",
          'closeWith' => '</ul>',
        ),
        'list-numeric' => array(
          'name' => t('Ordered List'),
          'className' => 'markitup-list-numeric',
          'openWith' => "<ol>\n",
          'closeWith' => '</ol>',
        ),
      );

      // Add the header buttons to the end
      foreach ($header_buttons as $tag => $details) {
        $settings['markupSet'][$tag] = $details;
        $context['profile']->settings['buttons']['html'][$tag] = 1;
      }

      // Add the list styles to the end
      foreach ($list_styles as $tag => $details) {
        $settings['markupSet'][$tag] = $details;
        $context['profile']->settings['buttons']['html'][$tag] = 1;
      }
      break;
  }
}