- πΊπΈUnited States jvogt Seattle, WA
I ran into this too and digging around it looks like it's because the filter has to disable caching (see token_filter_filter_info() in token_filter.module). See text_field_load() in text.module for details on how the safe_value is set. It only sets the safe_value if the filter format allows caching.
You can get the safe_value manually by passing the value through check_markup():
// $entity_wrapper is an entity_metadata_wrapper $field_value = $entity_wrapper->field_my_field->value(); $safe_value = $field_value['safe_value'] ?? check_markup($field_value['value'], $field_value['format']);
There's also an open issue with a patch to add a setting to toggle the caching: https://www.drupal.org/project/token_filter/issues/2055307 β