2

How can I remove or hide Format Options / Guideliness under the comments textarea in my theme?

enter image description here

2

If you're looking for a code-less way to do this in your theme. Adding a simple style rule to your theme's CSS can hide this element from display:

#edit-comment-body-wrapper .filter-wrapper { display: none; }
3

Check out the Better formats module. It allows you to hide the format options and tips link per user roles and fields.

3

The best is to add to your CSS file

.filter-wrapper
{
display: none;
}

There you go, disappeared!

2

Unfortunately this https://www.drupal.org/node/2599958 most likely won't get commited in any shape or form so you have to a) deny access to the route(if you want to) and add process handler for text_format via hook_element_info_alter.

/**
 * Implements hook_element_info_alter().
 */
function MODULENAME_element_info_alter(array &$types) {
  // Add process handler for text format so that we can remove
  // formatting tips.
  $types['text_format']['#process'][] = 'MODULENAME_process_text_format_element';
}

/**
 * Text input element process handler that will remove
 * the formatting tips.
 */
function MODULENAME_process_text_format_element(&$element, FormStateInterface $form_state, &$complete_form) {
  $element['format']['guidelines']['#access'] = FALSE;
  $element['format']['help']['#access'] = FALSE;
  return $element;
}
2

This is Another solution that i found in:
How to hide Input Format Options and help text under a textarea?

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

This is the method that I use:

/**
 * Implements hook_form_FORM_ID_alter().
 */
function MODULE_form_FORM_ID_alter(array &$form, FormStateInterface $form_state, $form_id) {
  // Here we only delete the format if the user is anonymous,
  // you can eliminate the if() for all the users.
  if (\Drupal::currentUser()->isAnonymous()) {
    $form['field_description']['widget']['#after_build'][] = '_mymodule_allowed_formats_remove_textarea_help';
  }
}

/**
 * Remove the textarea help message.
 *
 * @param array $form_element
 *   The form element.
 * @param FormStateInterface $form_state
 *   The form state.
 *
 * @return array
 *   Images URL Array.
 */
function _mymodule_allowed_formats_remove_textarea_help(array $form_element, FormStateInterface $form_state) {
  if (isset($form_element[0]['format'])) {
    // All this stuff is needed to hide the help text.
    unset($form_element[0]['format']['guidelines']);
    unset($form_element[0]['format']['help']);
    unset($form_element[0]['format']['#type']);
    unset($form_element[0]['format']['#theme_wrappers']);
    $form_element[0]['format']['format']['#access'] = FALSE;
  }

  return $form_element;
}

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.