function fontawesome_entity_presave in Font Awesome Icons 8.2
Implements hook_entity_presave().
File
- ./
fontawesome.module, line 411 - Drupal integration with Font Awesome, the iconic font for use with Bootstrap.
Code
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);
}
}
}
}
}
}