You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it possible to append a unique ID to the SVG identifier?
This should avoid trouble with same named SVG files from diffrent folders on same page, eg:
$fileAbsPath = GeneralUtility::getFileAbsFileName($file);
// early return if it seems that the file does not exist (is_file or file_exists, not sure here)
if (!is_file($fileAbsPath)) {
return '<!-- Please check path: ' . $file . ' -->';
}
$this->assetCollector->addXmlFile($fileAbsPath);
// feed in absolute path, to have same value as in AssetCollector Class
$iconIdentifier = $this->assetCollector->getIconIdentifierFromFileName($fileAbsPath);
and in the AssetCollector.php ~118 then:
public function getIconIdentifierFromFileName(string $xmlFile): string
{
// maybe other approach here for unique ID without messing up generated HTML to much
$uniqueId = substr(sha1($xmlFile), 0, 8);
return str_replace('.svg', '', basename($xmlFile)) . '-'. $uniqueId;
}
and in the AssetCollector.php ~102, too:
public function addXmlFile(string $xmlFile): void
{
// maybe security check, if file is in public path and a SVG file (is_file or file_exists, not sure here)
if (file_exists($xmlFile)) {
$this->xmlFiles[] = $xmlFile;
} else {
$xmlFile = preg_replace('/^\//', '', $xmlFile); // or: ltrim($xmlFile, '/');
$this->xmlFiles[] = GeneralUtility::getFileAbsFileName($xmlFile);
}
}
Best regards and many thanks for the extension :-)
The text was updated successfully, but these errors were encountered:
m-kappenberg
changed the title
Add unique value to SVG indentifier
Add unique Id to SVG indentifier
Jun 1, 2024
Is it possible to append a unique ID to the SVG identifier?
This should avoid trouble with same named SVG files from diffrent folders on same page, eg:
<ac:svg file="EXT:myext/Resources/Public/Svg/myIconFile.svg" class="b_myIconClass"/>
<ac::svg file="EXT:otherext/Resources/Public/Svg/myIconFile.svg" class="b_myIconClass"/>
<ac::svg file="fileadmin/myIconFile.svg" class="b_myIconClass"/>
Maybe change the SvgViewHelper.php from ~66:
to:
and in the AssetCollector.php ~118 then:
and in the AssetCollector.php ~102, too:
Best regards and many thanks for the extension :-)
The text was updated successfully, but these errors were encountered: