Code Monkey home page Code Monkey logo

assetcollector's People

Contributors

achimfritz avatar achimfritz-b13 avatar andreaskienast avatar bmack avatar davidsteeb avatar jschlier avatar neoblack avatar stegmatze avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

assetcollector's Issues

PHP Fatal error on 10LTS + PHP 7.4

When i make a composer updaten on a 10TLS PHP7.4 install version 2.x is loaded via composer. This leads to

PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function TYPO3\CMS\Core\Localization\LanguageServiceFactory::__construct(), 0 passed in /typo3/sysext/core/Classes/Utility/GeneralUtility.php on line 3492 and exactly 2 expected in typo3/sysext/core/Classes/Localization/LanguageServiceFactory.php:37

It seems like Version 2 needs PHP >= 8.0. There must be something wrong in the composer.json that i could load 2.x on 7.4

Compression of assets

Is it possible to add a option that allows the compression of css and js assets, similar to what is possible with typoscript?
The typo3 native assetcollector has unfortunately not received this option since version 10.3.

Thanks for your feedback.

Add unique Id to SVG indentifier

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

Not working in v13 with INT objects

Steps to reproduce:

  1. Add a simple INT object to the Page
  2. Clear page cache
  3. Make sure you are not logged in backend, delete BE login cookie to be sure
  4. View page in frontend, SVG with 'defs' is added
  5. Reload the page with the INT object several times
  6. The SVG with the 'defs' is only added the first time, after reloads it is gone

My solution:
I've completely removed the InlineSvgInjector Middleware, and added the SVG asset collector as footer data:

in ext_localconf.php add:

        $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'][]
            = \B13\Assetcollector\Hooks\PageRenderer\PostProcessHook::class . '->execute';

add Classes/Hooks/PageRenderer/PostProcessHook.php :

<?php

declare(strict_types=1);

namespace B13\Assetcollector\Hooks\PageRenderer;

use B13\Assetcollector\AssetCollector;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Http\ApplicationType;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

/**
 * PostProcessHook, this is referenced in ext_localconf.php
 * and should be executed once after all page rendering
 */
class PostProcessHook
{
    /**
     * @param array $params  The already used JS and CSS files and the header and footer data
     * @param PageRenderer $pageRenderer  The back reference to the TYPO3\CMS\Core\Page\PageRenderer class
     */
    public function execute(array &$params, PageRenderer &$pageRenderer): void
    {
        if (!($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface ||
            !ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend()) {
            return;
        }

        $assetCollector = GeneralUtility::makeInstance(AssetCollector::class);
// seems always empty, solution will follow
//        $cached = $this->getTypoScriptFrontendController()->config['b13/assetcollector'] ?? [];
//        if (!empty($cached['xmlFiles'] ?? null) && is_array($cached['xmlFiles'])) {
//            $assetCollector->mergeXmlFiles($cached['xmlFiles']);
//        }
        $svgReferences = $assetCollector->buildInlineXmlTag();
        $pageRenderer->addFooterData('<!-- SVG asset renderer -->' . PHP_EOL . $svgReferences);
        // not working with INT objects...
        //  $params['bodyContent'] = $params['bodyContent'] . '<!-- SVG asset renderer -->' . PHP_EOL . $svgReferences;
    }
// not used, see WIP comment above
    protected function getTypoScriptFrontendController(): ?TypoScriptFrontendController
    {
        return $GLOBALS['TSFE'] ?? null;
    }
}

Maybe you can check this solution?

I'm working on a solution for the "set SVG defs via TypoScript", too.

Best regards
Matthias

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.