Ocultar CKEditor

23/02/2016

El presente snippet deshabilita en Drupal 7 el texto enriquecido para todos los campos de tipo texto o texto largo. Deshabilita tanto la barra de herramientas de CKEditor como la selección de formatos de texto:

/**
 * 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;
}