Issue #3593706 by Etedal: Added a check to ensure $value is a string before running str_replace and preg_match in replaceContextAwareTokens(
Closes #3593706