Hiding the CKEditor

25/02/2016

This snippet disables the rich text in Drupal 7 for all the fields of type text or large text.  Additionally, it disables the CKEditor toolbar like the selection of the text format:

/**
 * Implements hook_form_alter().
 */
function module_form_alter(&$form, &$form_state, $form_id) {
  // Fields should have hidden the CKEditor.
  $fields = field_read_fields(array(
    'type' => array('text_long', 'text_with_summary'),
  ));
  callback_hide_wysiwyg($form, $fields);
}

/**
 * Hide CKEditor appeareance.
 *
 * Callback for module_form_alter().
 *
 * @param $form
 * @param $fields
 *   Fields with CKEditor that have to be disabled.
 *
 * @ingroup callbacks
 */
function callback_hide_wysiwyg(&$form, $fields) {
  foreach ($fields as $key => $value) {
    // Hide CKEditor appeareance.
    if (isset($form[$key])) {
      $form[$key][LANGUAGE_NONE][0]['#wysiwyg'] = FALSE;
      $form[$key]['#after_build'][] = 'callback_hide_text_format';
    }
  }
}

/**
 * Hide CKEditor text format.
 *
 * Callback for module_form_alter().
 *
 * @param $form
 *
 * @return mixed
 *   Same form without access to text formats.
 *
 * @ingroup callbacks
 */
function callback_hide_text_format(&$form) {
  // Hide CKEditor toolbar.
  $form[LANGUAGE_NONE][0]['format']['#access'] = FALSE;

  return $form;
}