I have a client with a D8 site who wants curly quotes and apostrophes on all rendered content. I was able to do this for the page titles with this preprocess function:
function mytheme_preprocess_page_title(&$variables) {
// Load the node entity from the current route
if ($node = \Drupal::request()->get('node')) {
// Get the title
$title = $node->getTitle();
// Replace left quotes
$title = preg_replace('/"(?=\w)/', '“', $title);
// Replace right quotes
$title = preg_replace('/(?<=\w)"/', '”', $title);
// Replace single quote/apostrophe
$title = str_replace("'", '’', $title);
// Return the title variable
$variables['title'] = t($title);
}
}
Is there a way to do this for the body field as well? hook_preprocess_field isn't getting me anywhere.