By gmak on
Hi,
I'm trying to expand the range of html tags that can be used in the 'Help Text' for fields. I’d like this to be applied to all fields.
I've been trying to use a D7 example and updating for D8/9, but I'm running into problems. This has led me to a lot of API stuff, that I'm not fully sure I'm understanding.
Here's what I've got:
function builder2020_field_widget_form_alter(&$element,&$form_state,&$context){
if(isset($element[0])){
$element[0]['#description'] = Xss::filter($context['instance']['description'], builder2020_field_filter_xss_allowed_tags());
}
}
// Provide a more permissive set of tags to be used with filter_xss()
function builder2020_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', 'div');
return array_merge(allowedTags, $new_tags);
}I think my problem is with the line:
return array_merge(allowedTags, $new_tags);and 'allowedTags' not being an array.
Can anyone point me in the right direction?
Comments
If you understand what
If you understand what allowed HTML tags does and how it works you'll have zero problems. However, unfortunately this never seems to be the case. Drupal 9 is Drupal 8 with the deprecated code removed. Drupal 7 and 6 use procedural code architecture. Drupal 8 and 9 use OOP architecture. Drupal 8 was built on top of Symfony which has excellent documentation and is OOP based.
Thanks. I guess I’m not as
Thanks. I guess I’m not as clear about this as I thought. I understand your point, but it doesn’t really help me get any closer to a solution. Can you help me understand what I need to do to my code to get it working?
One possible solution:
One possible solution: