Bug #87067

Add support for language -1 to TCA field type slug

Added by André Schließer 9 days ago. Updated 9 days ago.

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

0%

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

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

History

#1 Updated by André Schließer 9 days ago

  • Related to Bug #86623: tt_content - error when language content set to -1 added

#2 Updated by Gerrit Code Review 9 days ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59029

Also available in: Atom PDF