Project

General

Profile

Actions

Bug #87067

closed

Add support for language -1 to TCA field type slug

Added by André Buchmann over 5 years ago. Updated almost 5 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2018-12-03
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
9
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

Records with a TCA field from type slug can't be set to language -1:

#1522960188 InvalidArgumentException
Language -1 does not exist on site my-site.

As language -1 means all languages, I think the default language can used as a fallback to make the record editable again.
I found two possible locations to fix this issue:

A: Fix in InputSlugElement class directly for the slug field only

typo3/sysext/backend/Classes/Form/Element/InputSlugElement.php Line 225

protected function getPrefix(SiteInterface $site, int $requestLanguageId = 0): string
    {
        // original code
        $language = $site->getLanguageById($requestLanguageId);
        // proposed fix
        $language = ($requestLanguageId < 0) ? $site->getDefaultLanguage() : $site->getLanguageById($requestLanguageId);
        $base = $language->getBase();
        $baseUrl = (string)$base;
        $baseUrl = rtrim($baseUrl, '/');
        if (!empty($baseUrl) && empty($base->getScheme()) && $base->getHost() !== '') {
            $baseUrl = 'http:' . $baseUrl;
        }
        return $baseUrl;
    }

B: Fix in Site class

This is the function where the error is initially thrown. But as it is used on multiple locations I think it may breaks other things.

typo3/sysext/core/Classes/Site/Entity/Site.php Line 219

public function getLanguageById(int $languageId): SiteLanguage
    {
        if (isset($this->languages[$languageId])) {
            return $this->languages[$languageId];
        } elseif ($languageId === -1) { // handle all languages -1
            return $this->getDefaultLanguage();
        }
        throw new \InvalidArgumentException(
            'Language ' . $languageId . ' does not exist on site ' . $this->identifier . '.',
            1522960188
        );
    }

I prefer solution A, but maybe some core developer can evaluate this?
Thank you!


Related issues 2 (0 open2 closed)

Related to TYPO3 Core - Bug #86623: tt_content - error when language content set to -1Closed2018-10-10

Actions
Related to TYPO3 Core - Bug #87695: TCA type slug fails on records with sys_language_uid == -1Closed2019-02-12

Actions
Actions

Also available in: Atom PDF