Problem/Motivation
TextItem contains a processed property
This property is a computed field built with the TextProcessed class
Calling $entity->text_field->processed
will return you the filtered text, i.e. with all filters applied.
At this point if you're using $entity->text_field->processed
in a render array, you should also take care to collect its cacheable-metadata. Because TextProcessed implements CacheableDependencyInterface, you can do that like so
$cache = new CacheableMetadata();
$a_render_array = [
'#theme' => 'biscuits',
'#cookies' => $entity->text_field->processed,
];
$cache->addCacheableDependency($entity->text_field->processed);
$cache->applyTo($a_render_array);
However a the processed protected property on TextProcessed is an instance of FilterProcessResult, which extends from BubbleableMetadata, not just CacheableMetadata
This means there are #attachments inside it too, not just #cache entries.
There is no way to access those attachments and add them to your render array.
This is minor because you can work around this by doing this instead
$a_render_array = [
'#theme' => 'biscuits',
'#cookies' => [
'#type' => 'processed_text',
'#text' => $entity->text_field->value,
'#format' => $entity->text_field->format,
];
Steps to reproduce
Write a filter plugin that adds Javascript or CSS (or any #attached)
Add an input format with that filter plugin enabled
Create an entity with a text field on it
Access the contents of the field for use in a render array using $entity->text_field->processed
Note that your render array won't include the attachments
Proposed resolution
Have TextProcessed also implement AttachmentsInterface
Remaining tasks
Implement the interface
Add a test
User interface changes
API changes
Data model changes
Release notes snippet