Skip to content

Commit

Permalink
Merge pull request #130 from netresearch/issue-112_remove-wrapping-p-tag
Browse files Browse the repository at this point in the history
[BUGFIX] #112: Remove wrapping p-tag from images
  • Loading branch information
CybotTM authored Nov 6, 2021
2 parents 45f5d02 + c21cb85 commit 52367aa
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Classes/Controller/ImageLinkRenderingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function renderImages($conf)
// Get link inner HTML
$linkContent = $this->cObj->getCurrentVal();
// Find all images with file-uid attribute
$imgSearchPattern = '/<img(?=.*data-htmlarea-file-uid).*?\/>/';
$imgSearchPattern = '/<p\><img(?=.*src).*?\/><\/p>/';
$attrSearchPattern = '/([a-zA-Z0-9-]+)=["]([^"]*)"|([a-zA-Z0-9-]+)=[\']([^\']*)\'/';
$passedImages = [];
$parsedImages = [];
Expand All @@ -87,6 +87,8 @@ public function renderImages($conf)
preg_match_all($attrSearchPattern, $passedImage, $passedAttributes);
$passedAttributes = array_combine($passedAttributes[1], $passedAttributes[2]);

// The image is already parsed by netresearch linkrenderer, which removes custom attributes, so it will never match this condition.
// But we leave this as fallback for older render versions.
if (!empty($passedAttributes['data-htmlarea-file-uid'])) {
try {
$systemImage = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObject($passedAttributes['data-htmlarea-file-uid']);
Expand Down Expand Up @@ -127,13 +129,13 @@ public function renderImages($conf)
// Image template; empty attributes are removed by 3rd param 'false'
$parsedImages[] = '<img ' . GeneralUtility::implodeAttributes($imageAttributes, true, false) . ' />';
} catch (FileDoesNotExistException $fileDoesNotExistException) {
$parsedImages[] = $passedImage;
$parsedImages[] = strip_tags($passedImage , '<img>');
// Log in fact the file could not be retrieved.
$message = sprintf('I could not find file with uid "%s"', $passedAttributes['data-htmlarea-file-uid']);
$this->getLogger()->log(LogLevel::ERROR,$message);
}
} else {
$parsedImages[] = $passedImage;
$parsedImages[] = strip_tags($passedImage , '<img>');
}
}
// Replace original images with parsed
Expand Down

0 comments on commit 52367aa

Please sign in to comment.