Visibility settings have changed in D7 so it's now set per input format.

However, can one still disable ckeditor for certain textareas?

The case is when a cck field has 'filtered text' type input.
This creates a ckeditor instance on the form.
I'd rather a plain textarea that accepts some html. In this case it's a postal address.

thoughts?

DT

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dczepierga’s picture

Status: Active » Closed (works as designed)

Hi,

For now it's impossible to do that... This option (include/exlude from textareas) will be released with version 7.x-2.x of CKEditor module.
So pls be patient.

Hint: U could try also to disable it in ckeditor.module.php by adding special peace of code, that check the field name and then exit from function - so then CKEditor library would't be attached there.

If u have any questions pls reopen this issue.

Greetings

davidwhthomas’s picture

Thanks for the earlier reply, just an update on this if anyone else is looking.

In the meanwhile, in order to disable ckeditor autostart for a specific textarea, you can use javascript and go:

  // Disable default ckeditor on some textareas.
  Drupal.behaviors.ckeditor_noautostart = {
    attach: function(context) {
      // Subheading field off
      if ($('div.field-name-field-subheading').length > 0){
        if (typeof(Drupal.settings.ckeditor.autostart) != 'undefined' && typeof(Drupal.settings.ckeditor.autostart['edit-field-subheading-und-0-value']) != 'undefined') {
          delete Drupal.settings.ckeditor.autostart['edit-field-subheading-und-0-value'];
          $('div.field-name-field-subheading a.ckeditor_links').html('Switch to rich-text editor');
        }
      }
    }
  }  

In this case field_subheading

To disable ckeditor entirely on a field, it looks like one could use hook_element_info_alter and replace the ckeditor pre_render function ckeditor_pre_render_text_format with a clone copy that checks for specific fields. See ckeditor.module ~line 209 for more info

hth,

DT

jcisio’s picture

Issue summary: View changes
Status: Closed (works as designed) » Closed (duplicate)
Pete B’s picture

The original issue describes a use case which is not a duplicate of #1063986. Namely disabling with no option to enable (instead of disabling by default, but allowing to enable.)

I'm interested in the behaviour described here too. I have a field where I never want CKEditor to appear.

I would like to request a simple change to ckeditor_load_by_field() to add the following lines:

  foreach (module_implements('ckeditor_field_disable') as $module) {
    if (module_invoke($module, 'ckeditor_field_disable', $field, $format) == FALSE) {
      return $field;
    }
  }

Then I could use:

function MYMODULE_ckeditor_field_disable($field, $format) {
  if (my_reason_for_disabling_ckeditor()) {
    return FALSE;
  }
}

to disable CKEditor for my field.

Pete B’s picture

Status: Closed (duplicate) » Needs review
rudiedirkx’s picture

Status: Needs review » Needs work

I think a hook is too expensive, and it misses a lot of context. $field is not enough to know exactly where you are.

My approach in #2530324: Allow lazy loading per-element CKEditor by element #property was the other way around: alter a form, add a property, CKEditor will read that property when it's time to decide to enable the editor. Advantage: 100% context, because custom form alter. Disadvantage: lots of form alters if you're disabling many editors in different locations.

And a tiny bit of code review: if the hook doesn't return anything (NULL), it'll disable the field, because NULL == FALSE.

rudiedirkx’s picture

Actually, this issue might be about completely disabling CKEditor for one element. My issue was about only disabling autostart.

daniel.nitsche’s picture

It's a bit cheeky, but if you add a class of "ckeditor-processed" to the textarea and the parent div, ckeditor won't attempt to load for that field.

sumanthkumarc’s picture

Was looking for solution to disable ckeditor for my comment body field and #2 comment above helped me.
I found that ckeditor doesn't load if the attribute #format is unset, so did following in my pre_render function. Also i did array_unshift so that my function is at top.

unset($element['#format']); // ckeditor doesn't load if this is unset

rubenvarela’s picture

In case it helps someone. Meanwhile, what I did to disable it on a field is the following.

function hook_form_alter(&$form, &$form_state, $form_id) {
  //Disable CKEditor on text field.
  if($form_id == 'FORM_ID') {
    // entity page form
    $lang = $form['FIELD_TEXT']['#language'];
    $form['FIELD_TEXT'][$lang][0]['#wysiwyg'] = FALSE;
  } elseif(isset($form['field_ref'][LANGUAGE_NONE]['form']['#bundle']) && $form['field_ref'][LANGUAGE_NONE]['form']['#bundle'] == 'BUNDLE_NAME') {
    //entity reference
    foreach($form['field_ref'][LANGUAGE_NONE]['form']['FIELD_TEXT'][LANGUAGE_NONE] as &$element){
      $element[0]['#wysiwyg'] = FALSE;
    }
  }
}

- Things that need to be changed, FORM_ID, FIELD_TEXT, BUNDLE_NAME
- Assumption, LANGUAGE_NONE