Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
edited title
Link
leymannx
  • 18.8k
  • 6
  • 72
  • 126

Drupal 8: Apply How can I programmatically apply text formats programmatically?

Source Link
plambre
  • 215
  • 2
  • 11

Drupal 8: Apply text formats programmatically

I've created a custom text format I'm trying to apply to a field programmatically. As best I can tell, the format IS getting applied, but it is not stripping HTML tags like it is supposed to. The below screenshot shows how my text formatter is configured:

enter image description here

As you can see, its supposed to filter <span> tags. The Nodes where this will be used get created programmatically, and I apply the text formatter as follows:

'field_career_job_description1' => ['value' => $job['jobdesc'],'format' => 'careers_html_formatter']

This appears to be working correctly, if I print the variables passed to twig, I see that the formatter is, indeed, my custom format:

enter image description here

However, as you can see in the sshot, <span> tags are still in the text.

Note that I am displaying the field in question in Twig as follows:

{{ content.field_career_job_description1[0]['#text'] | raw }}