I have created a content type that has some tokens within the read-only body section so that other custom fields that the user enters when they create content based on this content type are mapped to its associated token within the body section. If the user enters information within a optional field then that entered information replaces the token when the node is saved. The problem is for optional fields when they don't enter a anything within it then the saved node contains the token name instead of an empty section which is what we want.
1 Answer
I have figured it out with my own custom module:
function mymodule_tokens_alter(&$replacements, $context) { if ($context['type'] == 'node') { $keys = array_keys($context['tokens']); foreach ($keys as $key) { if (isset($context['tokens'][$key]) && !isset($replacements[$context['tokens'][$key]])) { $replacements[$context['tokens'][$key]] = ''; } } } }