33

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

1
  • 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
    Commented Sep 28, 2011 at 15:01

19 Answers 19

27

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;
}
3
  • 2
    this works but has a side effect: it removes the wysiwyg editor from the text area
    – castaway
    Commented Dec 5, 2012 at 19:53
  • That did the trick for me. I mainly just wanted to clean up the text input.
    – RevNoah
    Commented Oct 2, 2013 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. Commented Jul 9, 2014 at 11:35
27

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.

4
  • 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
    Commented Oct 16, 2014 at 14:13
  • simplify didn't work consistently for me. in some cases it worked in others not.
    – snowguy
    Commented Jan 22, 2015 at 4:31
  • Didn't work for me. I've used bootstrap theme so maybe because of that.
    – sobi3ch
    Commented Mar 5, 2015 at 12:17
  • Simplify didn't work for me too. Commented Jan 10, 2018 at 13:17
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.

2
  • 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
    Commented Feb 12, 2013 at 5:07
  • Better formats works well for D7, is stable with no serious issues and a Beta 2 release in Jan 2016.
    – Duncanmoo
    Commented Feb 2, 2016 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;
}
4
  • +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. Commented Dec 21, 2014 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
    Commented Dec 23, 2014 at 8:51
  • Note: LANGUAGE_NONE is a constant with value und ... don't use und.
    – doublejosh
    Commented Mar 10, 2015 at 21:58
  • This kills the wysiwyg as well Commented Sep 10, 2015 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;
}
1
  • This is an excellent solution if you only want to hide it on one particular field. And the WYSIWYG stays functional.
    – Dalin
    Commented Jul 18, 2018 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.

7
  • 3
    I wouldnt recommend "although it works" CSS hiding.
    – saadlulu
    Commented Sep 3, 2013 at 13:39
  • not an answer, a getaway
    – Pan Chrono
    Commented Nov 11, 2013 at 12:56
  • 6
    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
    Commented Oct 16, 2014 at 14:07
  • 1
    I would prefer hiding it. +1 vote for you. Commented Nov 9, 2015 at 3:54
  • css injector module works wonders. see: prntscr.com/cieuvs Commented Sep 15, 2016 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;
}
1
  • This is a great technique if you want to hide it on many/all fields.
    – Dalin
    Commented Jul 18, 2018 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.

2
  • 6
    Only works if you only want to enable plain text. Because you can't disable that one.
    – Fletch
    Commented Aug 7, 2012 at 12:50
  • exactly. You can't have "Filtered Text" only. Sorry, but this answer is misleading.
    – nerdoc
    Commented Feb 9, 2016 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!

1
  • 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) Commented Sep 15, 2016 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.

1
  • 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.
    – avpaderno
    Commented Mar 22, 2012 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.

1
  • simplify works for other fields, but I couldn't make it work for input formats.
    – Druvision
    Commented Dec 11, 2013 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.

1
  • This is a great module but it makes the formats box collapsed, not toally hidden.
    – Druvision
    Commented Dec 11, 2013 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);
}
4
  • OP specified D7 in the question
    – Geoff
    Commented Jun 4, 2015 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. Commented Jun 5, 2015 at 16:03
  • that would be the better approach, only because the OP in this case is very specific about the version
    – Geoff
    Commented Jun 5, 2015 at 16:05
  • Could you please indicate how to implement it? How can i find form_id?
    – john
    Commented Feb 19, 2016 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']
0

Simplest solution is to just make the field "Text (plain, long)".

Done, no code, no modules, no headaches.


If you must allow some roles to have formatting while others plain text then the closest you can get without extra code or modules is to disable all other formats for that role that just needs plain text.

admin/config/content/formats

It still leaves the bar and the Help on Text Formats question mark. But eh, it's worth not having extra code.

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.