protected function EntityShareEmbeddedEntitiesEnhancer::updateImgSrc in Entity Share 8.3
Helper function to update an img tag's src attribute.
Parameters
array $matches: The img tag information.
Return value
string The replacement.
File
- src/
Plugin/ jsonapi/ FieldEnhancer/ EntityShareEmbeddedEntitiesEnhancer.php, line 163
Class
- EntityShareEmbeddedEntitiesEnhancer
- Alter rich text exposed data to provide import URL for embedded entities.
Namespace
Drupal\entity_share\Plugin\jsonapi\FieldEnhancerCode
protected function updateImgSrc(array $matches) {
$entity_type = $matches[2];
$entity_uuid = $matches[3];
if ($entity_type != 'file') {
return $matches[0];
}
$entities = $this->entityTypeManager
->getStorage($entity_type)
->loadByProperties([
'uuid' => $entity_uuid,
]);
if (!empty($entities)) {
/** @var \Drupal\file\FileInterface $entity */
$entity = array_shift($entities);
$new_src = $entity
->createFileUrl();
// Insert new src attribute.
return preg_replace('#src="(.*)"#U', 'src="' . $new_src . '"', $matches[0]);
}
return $matches[0];
}