3

When I use the widget "field-type-text-with-summary" with the CKEditor, my summary is shown in the CKEditor-format. Can I prevent this and display the field with the plain-format? Hooking into the form, I haven't found a format for the summary; there is just one for the whole body field.

using CKEditor module.

5
  • Are you using the CKEditor module, or the WYSIWYG module? Commented Nov 1, 2011 at 14:55
  • the CKEditor module Commented Nov 2, 2011 at 11:27
  • OK, I think using WYSIWYG instead of CKEditor will help your issue. See my answer below. Commented Nov 2, 2011 at 13:35
  • thank you, but I want/need to use the CKEditor module for better configuration. Commented Nov 2, 2011 at 15:21
  • and in drupal8 ?
    – Matoeil
    Commented Mar 23, 2018 at 9:26

7 Answers 7

2
+50

I believe the easier path is going with WYSIWYG module.

If you want to go with CKEditor, it sets the editor using hook_element_info_alter. It changes the widget for any form element of the type text_format, in every form built with drupal.

I went looking for the pre_render function CKEditor uses to set the editor up, and figured out a way to prevent it from showing up in summary fields only. First, we'll have to swap the CKEditor pre_render function for one of our own:

function MYMODULE_element_info_alter(&$types) {
  if (!empty($types['text_format']['#pre_render'])) {
    $types['text_format']['#pre_render'] = array_diff($types['text_format']['#pre_render'], array('ckeditor_pre_render_text_format'));
  }
  $types['text_format']['#pre_render'][] = 'MYMODULE_ckeditor_pre_render_text_format';
}

Your module must run its code after CKEditor, and you better declare it depends on CKEditor in the .info file.

Then copy the ckeditor_pre_render_text_format from CKEditor module to your module and change its name to MYMODULE_ckeditor_pre_render_text_format. You will notice it already has an if clause that checks whether $element['summary'] and loads CKEditor for both value and system. Just delete the line that sets it for summary. In version 1.4 (latest stable) the line looks like this:

$element['summary'] = ckeditor_load_by_field($element['summary'], $element['format']['format'], FALSE);
1
  • and in drupal8?
    – Matoeil
    Commented Mar 23, 2018 at 9:26
5

I solved this for the CKEditor module for Drupal 7 by altering the widget itself using hook_field_widget_WIDGET_TYPE_form_alter():

/**
 * Implements hook_field_widget_WIDGET_TYPE_form_alter().
 * Set the '#wysiwyg'-attribute to false for the summary fields.
 */
function YOURMODULE_field_widget_text_textarea_with_summary_form_alter(&$element, &$form_state, $context) {
  if (isset($element['summary']) && !isset($element['summary']['#wysiwyg'])) $element['summary']['#wysiwyg'] = false;
}

Hope this helps!

1
  • I used $element['summary']['#wysiwyg'] = false; in my hook_form_alter where I create the form. Works like a charm +1
    – FLY
    Commented Apr 17, 2013 at 14:12
1

Drupal doesn't have an input format for the summary: Both the summary and the body use the same input format.

1

Rather than use the CKEditor module use WYSIWYG (and place the CKEditor library in the sites/all/libraries directory). It will only apply the editor of choice to a particular input format so you don't need to mess around with disabling the editor on textareas where it's not needed. Using CKEditor with the WYSIWYG module will not apply the editor to the summary (like you want), although it is possible with hooks to add one if needed.

1

It is odd that the CKEditor module does not have this option. But until that happens, I created a module that inserts a #wysiwyg=FALSE via a #process function.

Use the CKeditor plain summary module.

0

You may be able to implement hook_form_alter and use the #wysiwyg parameter with a value of FALSE. I used this in Fill PDF to aid in preventing the WYSIWYG editor from appearing without having to set a separate ignore rule.

See this issue: http://drupal.org/node/285200 - looks like it's just been re-implemented. I never knew it had been removed!

0

Might have to take an approach similar to http://drupal.org/project/excerpt, (Drupal 6). Some details from the module's project page:

Excerpt module allows you to enter a separate excerpt/summary/teaser for a node, which does not have to be a cut off version of the body.

Even though Drupal 6 provides similar functionality, Excerpt is useful for various reasons, for instance, when also using editors like TinyMCE.

Have a look at the hooks used and something might be useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.