Skip to main content
edited tags
Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284
Question Protected by avpaderno
Notice removed Draw attention by 7wonders
Bounty Ended with Clive's answer chosen by 7wonders
added 1183 characters in body
Source Link
7wonders
  • 3.1k
  • 1
  • 25
  • 32

I want to display a simple table under a form field as part of the help text for that field (file field to be exact). Am I being totally mental or is there really no easy way of changing the allowed html tags for this text area? At the moment I have displayed:

Instructions to present to the user below this field on the editing form. Allowed HTML tags: a b big code del em i ins pre q small span strong sub sup tt ol ul li p br img

If there is no easy way, what is the next easiest way of doing it?

UPDATE:

Clive came up with a great way of doing it below with a custom module. You can also add to this using ctools to make the help text collapsible as follows:

// Implement hook_field_widget_form_alter()
function MYMODULE_field_widget_form_alter(&$element, &$form_state, &$context) {
  // If some condition is matched based on the element provided...
  if (isset($element[0]) && $element[0]['#field_name'] == 'field_test') {
    // Alter the description using your more permissive set of tags
    $reworked = filter_xss($context['instance']['description'], _MYMODULE_field_filter_xss_allowed_tags());
    $element[0]['#description'] = theme('ctools_collapsible', array('handle' => 'Help text', 'content' => $reworked, 'collapsed' => TRUE));
  }
}

// Provide a more permissive set of tags to be used with filter_xss()
function _MYMODULE_field_filter_xss_allowed_tags() {
  // Merge the new set of allowed tags with the less permissive defaults
  $new_tags = array('table', 'thead', 'tbody', 'tfoot', 'tr', 'th', 'td');
  return array_merge(_field_filter_xss_allowed_tags(), $new_tags);
}

I want to display a simple table under a form field as part of the help text for that field (file field to be exact). Am I being totally mental or is there really no easy way of changing the allowed html tags for this text area? At the moment I have displayed:

Instructions to present to the user below this field on the editing form. Allowed HTML tags: a b big code del em i ins pre q small span strong sub sup tt ol ul li p br img

If there is no easy way, what is the next easiest way of doing it?

I want to display a simple table under a form field as part of the help text for that field (file field to be exact). Am I being totally mental or is there really no easy way of changing the allowed html tags for this text area? At the moment I have displayed:

Instructions to present to the user below this field on the editing form. Allowed HTML tags: a b big code del em i ins pre q small span strong sub sup tt ol ul li p br img

If there is no easy way, what is the next easiest way of doing it?

UPDATE:

Clive came up with a great way of doing it below with a custom module. You can also add to this using ctools to make the help text collapsible as follows:

// Implement hook_field_widget_form_alter()
function MYMODULE_field_widget_form_alter(&$element, &$form_state, &$context) {
  // If some condition is matched based on the element provided...
  if (isset($element[0]) && $element[0]['#field_name'] == 'field_test') {
    // Alter the description using your more permissive set of tags
    $reworked = filter_xss($context['instance']['description'], _MYMODULE_field_filter_xss_allowed_tags());
    $element[0]['#description'] = theme('ctools_collapsible', array('handle' => 'Help text', 'content' => $reworked, 'collapsed' => TRUE));
  }
}

// Provide a more permissive set of tags to be used with filter_xss()
function _MYMODULE_field_filter_xss_allowed_tags() {
  // Merge the new set of allowed tags with the less permissive defaults
  $new_tags = array('table', 'thead', 'tbody', 'tfoot', 'tr', 'th', 'td');
  return array_merge(_field_filter_xss_allowed_tags(), $new_tags);
}
Tweeted twitter.com/#!/StackDrupal/status/162633763686334465
Notice added Draw attention by 7wonders
Bounty Started worth 50 reputation by 7wonders
Source Link
7wonders
  • 3.1k
  • 1
  • 25
  • 32

Changing Allowed HTML tags: @tags for help text input field

I want to display a simple table under a form field as part of the help text for that field (file field to be exact). Am I being totally mental or is there really no easy way of changing the allowed html tags for this text area? At the moment I have displayed:

Instructions to present to the user below this field on the editing form. Allowed HTML tags: a b big code del em i ins pre q small span strong sub sup tt ol ul li p br img

If there is no easy way, what is the next easiest way of doing it?