Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unique Id to SVG indentifier #23

Open
m-kappenberg opened this issue Jun 1, 2024 · 0 comments
Open

Add unique Id to SVG indentifier #23

m-kappenberg opened this issue Jun 1, 2024 · 0 comments

Comments

@m-kappenberg
Copy link

m-kappenberg commented 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:

        $this->assetCollector->addXmlFile($file);
        $iconIdentifier = $this->assetCollector->getIconIdentifierFromFileName($file);

to:

        $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 :-)

@m-kappenberg m-kappenberg changed the title Add unique value to SVG indentifier Add unique Id to SVG indentifier Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant