Skip to content

Fatal error when config.cdn_assets is not set #4

Description

@LeoniePhiline

Hi!
Thanks for building this little extension - it helps tremendously when building assets with webpack. :)

Problem

        if (($extensionConfig = $cache->get($configCacheIdentifier)) === false) { // (1)
            $systemConfig = $tsfe->config;

            if (isset($systemConfig['config']) && isset($systemConfig['config']['cdn_assets.'])) { // (2)
                $extensionConfig = $systemConfig['config']['cdn_assets.'];
            }

            try {
                // Remove dots from TypoScript array
                $extensionConfig = GeneralUtility::removeDotsFromTS($extensionConfig); // (3)

When no cache entry is returned at (1), then $extensionConfig is false.

Following, if isset($systemConfig['config']['cdn_assets.']) at (2) then GeneralUtility::removeDotsFromTS(array $array) will be called with a bool parameter, causing a Fatal Error:

Argument 1 passed to TYPO3\CMS\Core\Utility\GeneralUtility::removeDotsFromTS() must be of the type array, bool given

It might not be obvious why you'd ever want to not define config.cdn_assets - but on a multi-site TYPO3 installation this is not unusual at all, if you use asset manifests only for some of the sites in the page tree.

Solution

Option A

Set $extensionConfig to a sane [] value after (1):

        if (($extensionConfig = $cache->get($configCacheIdentifier)) === false) { // (1)
            $extensionConfig = [];
            $systemConfig = $tsfe->config;

            if (isset($systemConfig['config']) && isset($systemConfig['config']['cdn_assets.'])) { // (2)
                $extensionConfig = $systemConfig['config']['cdn_assets.'];
            }

            try {
                // Remove dots from TypoScript array
                $extensionConfig = GeneralUtility::removeDotsFromTS($extensionConfig); // (3)

Option B

Alternatively, use ?: when calling removeDotsFromTS() at (3):

                $extensionConfig = GeneralUtility::removeDotsFromTS($extensionConfig ?: []); // (3)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions