You are here

function wysiwyg_ckeditor_settings_form in Wysiwyg 7.2

Same name and namespace in other branches
  1. 6.2 editors/ckeditor.inc \wysiwyg_ckeditor_settings_form()

Enhances the editor profile settings form for CKEditor.

See also

http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html

2 string references to 'wysiwyg_ckeditor_settings_form'
hook_INCLUDE_editor in ./wysiwyg.api.php
Define a Wysiwyg editor library.
wysiwyg_ckeditor_editor in editors/ckeditor.inc
Plugin implementation of hook_editor().

File

editors/ckeditor.inc, line 222
Editor integration functions for CKEditor.

Code

function wysiwyg_ckeditor_settings_form(&$form, &$form_state) {
  $profile = $form_state['wysiwyg_profile'];
  $settings = $profile->settings;
  $installed_version = $form_state['wysiwyg']['editor']['installed version'];
  $ckeditor_defaults = array(
    'block_formats' => 'p,address,pre,h2,h3,h4,h5,h6,div',
    // Custom setting.
    'default_toolbar_grouping' => FALSE,
    'forcePasteAsPlainText' => FALSE,
    'resize_enabled' => TRUE,
    'simple_source_formatting' => FALSE,
    'toolbarLocation' => 'top',
    'allowedContent' => TRUE,
  );
  if (version_compare($installed_version, '3.1.0', '>=')) {

    // Enabled by default.
    $ckeditor_defaults['pasteFromWordRemoveFontStyles'] = TRUE;
    $ckeditor_defaults['pasteFromWordRemoveStyles'] = TRUE;
  }
  if (version_compare($installed_version, '4.6.0', '>=')) {

    // Disabled by default, deprecated.
    $ckeditor_defaults['pasteFromWordRemoveFontStyles'] = FALSE;

    // Dropped, no effect.
    unset($ckeditor_defaults['pasteFromWordNumberedHeadingToList'], $ckeditor_defaults['pasteFromWordRemoveStyles']);
  }
  if (version_compare($installed_version, '3.2.1', '>=')) {
    $ckeditor_defaults['stylesSet'] = '';
  }
  $settings += $ckeditor_defaults;
  $form['appearance']['toolbarLocation'] = array(
    '#type' => 'select',
    '#title' => t('Toolbar location'),
    '#default_value' => $settings['toolbarLocation'],
    '#options' => array(
      'bottom' => t('Bottom'),
      'top' => t('Top'),
    ),
    '#description' => t('This option controls whether the editor toolbar is displayed above or below the editing area.') . ' ' . t('Uses the <a href="@url">@setting</a> setting internally.', array(
      '@setting' => 'toolbarLocation',
      '@url' => url('http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-toolbarLocation'),
    )),
  );
  $form['appearance']['resize_enabled'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable resizing button'),
    '#default_value' => $settings['resize_enabled'],
    '#return_value' => 1,
    '#description' => t('This option gives you the ability to enable/disable the editor resizing feature.') . ' ' . t('Uses the <a href="@url">@setting</a> setting internally.', array(
      '@setting' => 'resize_enabled',
      '@url' => url('http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-resize_enabled'),
    )),
  );
  $form['output']['simple_source_formatting'] = array(
    '#type' => 'checkbox',
    '#title' => t('Apply simple source formatting'),
    '#default_value' => $settings['simple_source_formatting'],
    '#return_value' => 1,
    '#description' => t('If enabled, the editor will re-format the HTML source code using a simple set of predefined rules. Disabling this option could avoid conflicts with other input filters.') . ' ' . t('Uses the <a href="@url">@setting</a> setting internally.', array(
      '@setting' => 'dataProcessor.write.setRules()',
      '@url' => url('http://docs.cksource.com/ckeditor_api/symbols/src/plugins_htmlwriter_plugin.js.html'),
    )),
  );
  $form['paste'] = array(
    '#type' => 'fieldset',
    '#title' => t('Paste plugin'),
    '#description' => t('Settings for the <a href="@url">@plugin</a> plugin.', array(
      '@plugin' => 'paste',
      '@url' => url('http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-forcePasteAsPlainText'),
    )),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'advanced',
  );
  $form['paste']['forcePasteAsPlainText'] = array(
    '#type' => 'checkbox',
    '#title' => t('Force paste as plain text'),
    '#default_value' => !empty($settings['forcePasteAsPlainText']),
    '#return_value' => 1,
    '#description' => t('If enabled, all pasting operations insert plain text into the editor, losing any formatting information possibly available in the source text. Note: Paste from Word is not affected by this setting.') . ' ' . t('Uses the <a href="@url">@setting</a> setting internally.', array(
      '@setting' => 'forcePasteAsPlainText',
      '@url' => url('http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-forcePasteAsPlainText'),
    )),
  );
  if (version_compare($installed_version, '3.1.0', '>=')) {
    $form['paste']['pasteFromWord'] = array(
      '#type' => 'fieldset',
      '#title' => t('Paste from Word'),
    );
    $form['paste']['pasteFromWord']['pasteFromWordNumberedHeadingToList'] = array(
      '#type' => 'checkbox',
      '#title' => t('Numbered heading to list'),
      '#default_value' => !empty($settings['pasteFromWordNumberedHeadingToList']),
      '#return_value' => 1,
      '#description' => t('If enabled, transforms MS Word outline numbered headings into lists.'),
    );
    $form['paste']['pasteFromWord']['pasteFromWordPromptCleanup'] = array(
      '#type' => 'checkbox',
      '#title' => t('Prompt on cleanup'),
      '#default_value' => !empty($settings['pasteFromWordPromptCleanup']),
      '#return_value' => 1,
      '#description' => t('If enabled, prompts the user about the clean up of content being pasted from MS Word.'),
    );
    $form['paste']['pasteFromWord']['pasteFromWordRemoveFontStyles'] = array(
      '#type' => 'checkbox',
      '#title' => t('Remove font styles'),
      '#default_value' => !empty($settings['pasteFromWordRemoveFontStyles']),
      '#return_value' => 1,
      '#description' => t('If enabled, removes all font related formatting styles, including font size, font family, font foreground/background color.'),
    );
    $form['paste']['pasteFromWord']['pasteFromWordRemoveStyles'] = array(
      '#type' => 'checkbox',
      '#title' => t('Remove styles'),
      '#default_value' => !empty($settings['pasteFromWordRemoveStyles']),
      '#return_value' => 1,
      '#description' => t('If enabled, removes element styles that can not be managed with the editor, other than font specific styles.'),
    );
  }
  if (version_compare($installed_version, '4.1.0', '>=')) {
    $form['output']['acf'] = array(
      '#type' => 'fieldset',
      '#title' => t('Advanced Content Filter'),
      '#description' => t('ACF limits and adapts input data (HTML code added in source mode or by the editor.setData method, pasted HTML code, etc.) so it matches the editor configuration in the best possible way. It may also deactivate features which generate HTML code that is not allowed by the configuration. See <a href="@url">@url</a> for details.', array(
        '@url' => url('http://docs.ckeditor.com/#!/guide/dev_advanced_content_filter'),
      )),
    );
    $form['output']['acf']['acf_mode'] = array(
      '#type' => 'select',
      '#title' => t('Mode'),
      '#options' => array(
        WYSIWYG_CKEDITOR_ACF_AUTOMATIC => t('Automatic'),
        WYSIWYG_CKEDITOR_ACF_CUSTOM => t('Custom'),
        WYSIWYG_CKEDITOR_ACF_DISABLED => t('Disabled'),
      ),
      '#default_value' => isset($profile->settings['acf_mode']) ? $profile->settings['acf_mode'] : WYSIWYG_CKEDITOR_ACF_DISABLED,
      '#description' => t('If set to <em>Automatic</em> or <em>Custom</em>, the editor will strip out any content not explicitly allowed <strong>when the editor loads</strong>.'),
    );
    $form['output']['acf']['acf_allowed_content'] = array(
      '#type' => 'textarea',
      '#title' => t('Content Rules'),
      '#default_value' => isset($profile->settings['acf_allowed_content']) ? $profile->settings['acf_allowed_content'] : '',
      '#description' => t('Rules for whitelisting content for the advanced content filter. Both string and object formats accepted. Uses the <a href="@allowed_url">allowedContent</a> setting in <em>Custom</em> mode <strong>or</strong> the <a href="@allowed_extra_url">extraAllowedContent</a> settings in <em>Automatic</em> mode internally. See <a href="@info_url">@info_url</a> for details.', array(
        '@info_url' => url('http://docs.ckeditor.com/#!/guide/dev_allowed_content_rules'),
        '@allowed_url' => url('http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-allowedContent'),
        '@allowed_extra_url' => url('http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-extraAllowedContent'),
      )),
      '#states' => array(
        'visible' => array(
          ':input[name="acf_mode"]' => array(
            array(
              'value' => WYSIWYG_CKEDITOR_ACF_AUTOMATIC,
            ),
            array(
              'value' => WYSIWYG_CKEDITOR_ACF_CUSTOM,
            ),
          ),
        ),
      ),
      '#element_validate' => array(
        'wysiwyg_ckeditor_settings_form_validate_allowed_content',
      ),
    );
  }
  if (version_compare($installed_version, '3.6.0', '>=')) {
    $form['appearance']['default_toolbar_grouping'] = array(
      '#type' => 'checkbox',
      '#title' => t('Use default toolbar button grouping'),
      '#default_value' => !empty($settings['default_toolbar_grouping']),
      '#return_value' => 1,
      '#description' => t('This option gives you the ability to enable/disable the usage of default groupings for toolbar buttons. If enabled, toolbar buttons will be placed into predetermined groups instead of all in a single group.'),
    );
  }
  if (version_compare($installed_version, '3.2.1', '>=')) {

    // Versions below 3.2.1 do not support Font styles at all.
    $form['css']['stylesSet'] = array(
      '#type' => 'textarea',
      '#title' => t('CSS classes'),
      '#description' => t('Optionally define CSS classes for the "Font style" dropdown list.<br />Enter one class on each line in the format: !format. Example: !example<br />If left blank, CSS classes are automatically imported from loaded stylesheet(s).', array(
        '@url' => url('http://docs.ckeditor.com/#!/api/CKEDITOR.stylesSet'),
        '!format' => '<code>[label]=[element].[class]</code>',
        '!example' => '<code>Title=h1.title</code>',
      )) . ' ' . t('Uses the <a href="@url">@setting</a> setting internally.', array(
        '@setting' => 'stylesSet',
        '@url' => url('http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-stylesSet'),
      )),
      '#default_value' => $settings['stylesSet'],
      '#element_validate' => array(
        'wysiwyg_ckeditor_settings_form_validate_stylessets',
      ),
    );
  }
  if (version_compare($installed_version, '4.6.0', '>=')) {
    $form['paste']['pasteFromWord']['pasteFromWordRemoveFontStyles']['#description'] .= '<br />' . t('This setting will be deprecated in the future. Use ACF to replicate the effect of enabling it.');
    unset($form['paste']['pasteFromWord']['pasteFromWordNumberedHeadingToList'], $form['paste']['pasteFromWord']['pasteFromWordRemoveStyles']);
  }
  $form['css']['block_formats'] = array(
    '#type' => 'textfield',
    '#title' => t('Block formats'),
    '#default_value' => $settings['block_formats'],
    '#size' => 40,
    '#maxlength' => 250,
    '#description' => t('Comma separated list of HTML block formats. Possible values: <code>@format-list</code>.', array(
      '@format-list' => 'p,h1,h2,h3,h4,h5,h6,div,blockquote,address,pre,code,dt,dd and other block elements',
    )) . ' ' . t('Uses the <a href="@url">@setting</a> setting internally.', array(
      '@setting' => 'block_formats',
      '@url' => url('http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-format_tags'),
    )),
  );
}