Problem/Motivation
Steps to reproduce
When running a batch process on content type with a wysiwyg field that uses a font awesome widget. The batch process errors out and the following message appears:
Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /app/web/modules/contrib/fontawesome/fontawesome.module on line 431
Proposed resolution
We will need to create a patch for the line of code where the preg_replace function is used and use a "Null Coalescing Operator" for the third argument in that function. The "Null Coalescing Operator" method is referenced in https://www.php.net/manual/en/language.operators.comparison.php#language...
/**
* Implements hook_entity_presave().
*/
function fontawesome_entity_presave(EntityInterface $entity) {
if ($entity instanceof ContentEntityInterface) {
// Loop over the fields.
foreach ($entity->getFields() as $fields) {
if ($fields instanceof ItemList) {
// If this is a text field (uses an editor).
if (in_array($fields->getFieldDefinition()->getType(), [
'text',
'text_long',
'text_with_summary',
])) {
foreach ($fields as $field) {
// Find and replace SVG strings with original icon HTML.
$fieldValue = $field->getValue();
$fieldValue['value'] = preg_replace('%<svg .*?class="svg-inline--fa.*?<\/svg><!--\s?(<(span|i).*?<\/(span|i)>).*\s?-->%', '$1', $fieldValue['value']);
$field->setValue($fieldValue);
}
}
}
}
}
}
Needs to be replaced with
/**
* Implements hook_entity_presave().
*/
function fontawesome_entity_presave(EntityInterface $entity) {
if ($entity instanceof ContentEntityInterface) {
// Loop over the fields.
foreach ($entity->getFields() as $fields) {
if ($fields instanceof ItemList) {
// If this is a text field (uses an editor).
if (in_array($fields->getFieldDefinition()->getType(), [
'text',
'text_long',
'text_with_summary',
])) {
foreach ($fields as $field) {
// Find and replace SVG strings with original icon HTML.
$fieldValue = $field->getValue();
$fieldValue['value'] = preg_replace('%<svg .*?class="svg-inline--fa.*?<\/svg><!--\s?(<(span|i).*?<\/(span|i)>).*\s?-->%', '$1', $fieldValue['value'] ?? '');
$field->setValue($fieldValue);
}
}
}
}
}
}
Remaining tasks
Create a patch the replaces the third argument for the function preg_replace with a "Null Coalescing Operator"