32

How to hide Input Format Options and help text under a textarea when adding|editing a node?

Screenshot - part to hide selected with red rectangle

  • I think that you can do it if you access the form through hook_form_alter however I'm not sure about the details, so I'll not post this as an answer... – acm Sep 28 '11 at 15:01

18 Answers 18

26

For Drupal 7, you can use the Simplify module. It allows you to hide the Text Format options textarea, as well as other elements on node forms.

  • 3
    If you look at its source (cgit.drupalcode.org/simplify/tree/simplify.module?id=7681b0e), the module use jQuery to hide the text format options. It's a shame because 1: you only want to hide text format and do not need the whole module and 2: javascript becomes a requirement. Why not just hide it with CSS like Ionut Adrian Luchian's answer suggests ? It's definetly appropriate and clean. – B2F Oct 16 '14 at 14:13
  • simplify didn't work consistently for me. in some cases it worked in others not. – snowguy Jan 22 '15 at 4:31
  • Didn't work for me. I've used bootstrap theme so maybe because of that. – sobi3ch Mar 5 '15 at 12:17
  • Simplify didn't work for me too. – Артем Ильин Jan 10 '18 at 13:17
25

You can use hook_form_alter in a custom module to do this.

For instance, in drupal 7:

// hook_form_alter function
function CUSTOM_MODULE_form_alter(&$form, &$form_state, $form_id) {
    // We want this on a specific node type
    if ($form_id == 'NODE_TYPE_node_form') {
        $form['#after_build'][] = 'CUSTOM_MODULE_NODE_TYPE_node_form_after_build';
    }
}

// afterbuild function
function CUSTOM_MODULE_NODE_TYPE_node_form_after_build($form) {
    // We want this on a specific field
    $form['YOUR_FIELD']['und']['0']['format']['#access'] = FALSE;
    return $form;
}
  • 2
    this works but has a side effect: it removes the wysiwyg editor from the text area – castaway Dec 5 '12 at 19:53
  • That did the trick for me. I mainly just wanted to clean up the text input. – RevNoah Oct 2 '13 at 23:07
  • 1
    its better to mention LANGUAGE_NONE instead of 'und' and also the after_build function should have an role based checking in case other superior roles may view the Text Format box. – Aneek Mukhopadhyay Jul 9 '14 at 11:35
12

In drupal 6 there is the module Better Formats which does exactly what you want, there is a 7 dev version but it comes with a warning that it's under heavy development. If you site is still in development then it might be worth giving it a shot.

  • Seemed to work well for users that weren't admin, even if you remove the permissions for the admin group, user 1 will still see the options in D7 – joelpittet Feb 12 '13 at 5:07
  • Better formats works well for D7, is stable with no serious issues and a Beta 2 release in Jan 2016. – Duncanmoo Feb 2 '16 at 20:19
9

You can actually just kill the format form item.

function MY_THEME_form_comment_form_alter(&$form, &$form_state, &$form_id) {
  $form['comment_body']['#after_build'][] = 'MY_THEME_configure_comment_form';
}

function MY_THEME_configure_comment_form(&$form) {
  unset($form[LANGUAGE_NONE][0]['format']);
  return $form;
}
  • +1, the best solution. For future visitors, replace CUSTOM with your active theme's name. This code snippet should go in your template.php script in active theme's folder. And if your site has enabled for multilanguage, replace LANGUAGE_NONE with your language code. – Janaka R Rajapaksha Dec 21 '14 at 15:53
  • 2
    CUSTOM is intended as your custom theme name. You should NEVER hard code a language, if you need the active language use global $language; to grab it. – doublejosh Dec 23 '14 at 8:51
  • Note: LANGUAGE_NONE is a constant with value und ... don't use und. – doublejosh Mar 10 '15 at 21:58
  • This kills the wysiwyg as well – digitgopher Sep 10 '15 at 20:40
7

I think the best solution is, to disallow the access to the text format selection element. If you completely unset it, you will face unwanted side effects as a disappearing WYSIWYG editor. So I propose the following code.

function MY_MODULE_form_comment_form_alter(&$form, &$form_state, &$form_id) {
  $form['comment_body']['#after_build'][] = 'MY_MODULE_hide_text_format';
}


function MY_MODULE_hide_text_format(&$form) {
  $form[LANGUAGE_NONE][0]['format']['#access'] = false;
  return $form;
}
  • This is an excellent solution if you only want to hide it on one particular field. And the WYSIWYG stays functional. – Dalin Jul 18 '18 at 16:32
6

Use CSS, the easiest way. Firebug

#body-add-more-wrapper #edit-body-und-0-format {display: none;}

The power of CSS and Firebug

Good luck.

  • 3
    I wouldnt recommend "although it works" CSS hiding. – saadlulu Sep 3 '13 at 13:39
  • not an answer, a getaway – Pan Chrono Nov 11 '13 at 12:56
  • 5
    Why ? This is a great answer because the question is to hide it, not to remove it. It's not like hiding it would cause a security threat or be bad for SEO... You already define permissions in text format configuration so where is the problem ? – B2F Oct 16 '14 at 14:07
  • 1
    I would prefer hiding it. +1 vote for you. – Eliyah Nov 9 '15 at 3:54
  • css injector module works wonders. see: prntscr.com/cieuvs – Patoshi パトシ Sep 15 '16 at 18:32
5

FOR Drupal 7

function MODULENAME_element_info_alter(&$type) {
  if (isset($type['text_format']['#process'])) {
    foreach ($type['text_format']['#process'] as &$callback) {

      if ($callback === 'filter_process_format') {
        $callback = 'MODULENAME_filter_process_format';
      }
    }
  }
}


function MODULENAME_filter_process_format($element) {
  $element = filter_process_format($element);

  // Change input format to "Filtered HTML" for body fields of NODETYPE_NAME

  if ($element['#bundle'] == 'NODETYPE_NAME' && $element['#field_name'] == 'body') {

    $element['format']['format']['#default_value'] = 'filtered_html';
    $element['format']['format']['#format'] = 'filtered_html';  
    $element['format']['format']['#value']  = 'filtered_html';
    $element['#format'] = 'filtered_html';

  }
  return $element;
}
  • This is a great technique if you want to hide it on many/all fields. – Dalin Jul 18 '18 at 16:32
2

The another simple way to hide the input format option is removing all other input format from the user profiles you want to hide the option. For this, go admin->configuration->input formats and remove all the user roles from all other input format except one you want to give by default.

  • 6
    Only works if you only want to enable plain text. Because you can't disable that one. – Fletch Aug 7 '12 at 12:50
  • exactly. You can't have "Filtered Text" only. Sorry, but this answer is misleading. – nerdoc Feb 9 '16 at 21:02
2

I did this:

Unchecked "Use the Filtered HTML text format" and "Administer text formats and filters" from people > permissions for anonymous and authorized users so that they couldn't use CKeditor.

Of course you can disable it from CSS by "display: none;" for particular div class (it's .filter-wrapper) and hide all area you have pointed upper but in this case the area is hidden for everyone including superuser.

1

Install CSS Injector module (currently there is only a working development version for Drupal 8).

Then go to the administration page of CSS Injector (/admin/config/development/css-injector). Create a new CSS rule with this code (or any code that apply to a class of the formating area text):

.filter-guidelines {
    display: none;
}

Choose to apply it on Seven theme (or any admin theme in use). Save and enjoy!

  • Install the css injector 1.x as 2.0 is older. Here's a preview of how it looks: prntscr.com/cieuvs -- This module works wonders for css injection vs other modules like CPN (code per node) – Patoshi パトシ Sep 15 '16 at 18:31
0

You can't remove the "Plain text" input format. And the RTE is not showing when you use the "Plain Text" input format.

I will be using the CSS option.

  • The input format selector is not appearing when the currently logged-in user can use just an input format; that sole input format could be a different one, and the selector would not appear the same. – kiamlaluno Mar 22 '12 at 14:31
0

I use both "removing all other input format from the user profiles" and css way.

0

Try out simplify module .

Simplify allows particular fields to be hidden from the user interface. This helps to de-clutter forms and present a more user-friendly experience to content editors.

  • simplify works for other fields, but I couldn't make it work for input formats. – Druvision Dec 11 '13 at 10:30
0

If you want to hide the formats but still keep them available, try the "Simplified formats" module: https://www.drupal.org/project/simplified_formats

It hides the formats details in a little question mark icon next to the format selection dropdown. For many text format filters it really does no good to completely hide the instructions that tell one how to use them. Other filters are more automatic. I think we need a module that allows us to choose what shows up to the end user and what does not.

0

You can also use the Hide formats module.

Hide Formats allows you to collapse the "text format" or "input format" dropdowns to clean up the UI.

  • This is a great module but it makes the formats box collapsed, not toally hidden. – Druvision Dec 11 '13 at 10:31
0

For Drupal 8. This removes the format area for two fields.

/**
 * Implements hook_form_FORM_ID_alter().
 */
function CUSTOM_MODULE_form_FORM_ID_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  $form['#after_build'][] = 'CUSTOM_MODULE_eform_application_after_build';
}

function CUSTOM_MODULE_eform_application_after_build ($form) {
  unset($form['field_experience']['widget'][0]['format']);
  unset($form['field_miscellaneous']['widget'][0]['format']);
  return ($form);
}
  • OP specified D7 in the question – Geoff Jun 4 '15 at 2:08
  • 1
    Agreed. However, there is very little online for D8 at this point. I suppose I could make my own question and then answer it. Never tried that. – Andre Angelantoni Jun 5 '15 at 16:03
  • that would be the better approach, only because the OP in this case is very specific about the version – Geoff Jun 5 '15 at 16:05
  • Could you please indicate how to implement it? How can i find form_id? – john Feb 19 '16 at 4:20
0

For Drupal 7, you can:

1) Use hook_theme_registry_alter(&$theme_registry) from within a module to alter the theme registry, eq. the theme processors definition.

2) Then alter three theme functions, theme_filter_tips, theme_filter_tips_more_info, and theme_filter_guidelines, and force them to return nothing. As follows:

This is the target function. All of the above theme functions will be redirected to that.

function _mymodule_filter_tips($tips, $long = FALSE, $extra = ''){
  return '';
}

/**
 * Implements hook_theme_registry_alter
 */
function mymodule_theme_registry_alter(&$theme_registry) {
  $theme_registry['filter_tips']['theme path'] = drupal_get_path( 'module', 'mymodule' );
  $theme_registry['filter_tips']['function'] = '_mymodule_filter_tips';
  $theme_registry['filter_guidelines']['theme path'] = drupal_get_path( 'module', 'mymodule' );
  $theme_registry['filter_guidelines']['function'] = '_mymodule_filter_tips';
  $theme_registry['filter_tips_more_info']['theme path'] = drupal_get_path( 'module', 'mymodule' );
  $theme_registry['filter_tips_more_info']['function'] = '_mymodule_filter_tips';
}

When you clear your cache, Drupal will seek those filter definitions on the path of your module of choice (see drupal_get_path), and return nothing for each filter. Hence, no more text format descriptions.

0
/ hook_form_alter function
function CUSTOM_MODULE_form_alter(&$form, &$form_state, $form_id) {
    // We want this on a specific node type
    if ($form_id == 'NODE_TYPE_node_form') {
        $form['#after_build'][] = 'CUSTOM_MODULE_NODE_TYPE_node_form_after_build';
    }
}

// afterbuild function
function CUSTOM_MODULE_NODE_TYPE_node_form_after_build($form) {

    // We want to hide input formats and we can do it like following
    $form['body']['und']['0']['format']= '<div style="display:none;">';
    $form['body']['und']['0']['format']= '</div>';   

    return $form;
}

Mostly Worked for me with these small changes.

$form['body'][LANGUAGE_NONE][0]['format']['#prefix']<br>
$form['body'][LANGUAGE_NONE][0]['format']['#suffix']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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