1

I'm getting the value of a wysiwyg field in a preprocessor then passing it to Twig in a #markup render array. Everything works as expected with the exception of embedded images. I've modified the list of XSS allowed tags to allow the drupal-entity tag. However, it seems that this is being passed to Twig after the EntityEmbedFilter has opened and closed.

I'd like to use EntityEmbedFilter process function to process the value of my field prior to passing it to Twig. However, when trying to instantiate an instance of EntityEmbedFilter with the new keyword, I get an an error because the constructor requires a configuration array.

2

Considering letting Drupal do the work for you. Instead of calling things yourself, just let Drupal render it for you using a specific text format, which is configured to use entity embed.

See how check_markup() works, you could call that, but since you seem to be in a context where you want a render array anyway, just do what it does and use #type processed_text with #type and #format.

If that is for some reason not possible, then you need to mark the resulting object as a safe string by wrapping it with an object that implements MarkupInterface, for example with Markup::create() although that is marked as internal.

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.