TypeError when trying to replace tokens for custom fields that don't exist
TypeError: Return value of CRM_Core_EntityTokens::getCustomFieldName() must be of the type string, none returned is being thrown when trying to replace
custom_123 tokens for custom fields that don't exist.
- For a contact, choose the action Print/Merge Document
- In the message body field, enter a token for a custom field, that does not exist, e.g.
- Hit Preview or Download Document
This is just an example, the error occurs everywhere a non-existent custom field token is being fed into the token system.
PHP fatals with a 500 with an error message
TypeError: Return value of CRM_Core_EntityTokens::getCustomFieldName() must be of the type string, none returned in CRM_Core_EntityTokens->getCustomFieldName() (Line 511 of /path/to/civicrm/core/CRM/Core/EntityTokens.php).
Invalid tokens should just be ignored or replaced with an empty string (not sure what the previous behavior was).
\CRM_Core_EntityTokens::getCustomFieldName() should not be type hinted to
string for its return value when it can't keep that promise.
If the token systems really requires validating token names before calling this code path, this should be clearly documented and done within Core.