Issue Bug Closed

#95688Storage folder outside of page tree does not allow translations

Tizian Schmidlin 10/18/21, 11:39 updated 06/10/24, 18:15

Description

I’ve recently ran into an issue regarding translation on storage folders that are located outside of the main page trees where I was in some cases unable to translate the folder itself or create new translations for records situated inside of this folder.

Linux
PHP 7.4
TYPO3 10.4.20 + 10.4.21

The LocalConfiguration.php defines all available languages and moving the folder inside on of the page trees allows me to properly translate the folder and its contained records.

Comparing this to a copy of the same system with an earlier version of TYPO3 (10.4.17) I see that this works as I’d expect it. I’ve copied the configuration and the database from the 10.4.20 system to the 10.4.17 system and the behaviour stays as expected in the 10.4.17 version, so I guess there is something wrong there.

I’ve not started any further investigations in what might be the issue yet, but I’ll go down that rabbit-hole this afternoon.

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

History 5

  1. Tizian Schmidlin commented 10/18/21, 12:07

    Well, that was faster than expected.
    {{collapse(Show diff from 10.4.17 to 10.4.20,Hide diff)

    @@ -2246,7 +2242,7 @@ class EditDocumentController
          *                hidden. If set to another value, the query will select all sys_language records that has a
          *                translation record on that page (and is not hidden, unless you are admin user)
          * @param string $table For pages we want all languages, for other records the languages of the page translations
    -     * @return SiteLanguage[] Language
    +     * @return array Array with languages (uid, title, ISOcode, flagIcon)
          */
         protected function getLanguages(int $id, string $table): array
         {
    @@ -2266,14 +2262,13 @@ class EditDocumentController
                 }
                 $pageId = $id;
             }
    -        try {
    -            $site = GeneralUtility::makeInstance(SiteFinder::class)->getSiteByPageId($pageId);
    -        } catch (SiteNotFoundException $e) {
    -            $site = new NullSite();
    -        }
    -
             // Fetch the current translations of this page, to only show the ones where there is a page translation
    -        $allLanguages = $site->getAvailableLanguages($this->getBackendUser(), false, $pageId);
    +        $allLanguages = array_filter(
    +            GeneralUtility::makeInstance(TranslationConfigurationProvider::class)->getSystemLanguages($pageId),
    +            static function (array $language): bool {
    +                return (int)$language['uid'] !== -1;
    +            }
    +        );

    }}

    Looking into the TranslationConfigurationProvider class explains why this does not behave in the same way as before:

    {{collapse(Show code exerpt, Hide code exerpt)

    if ($pageId === 0) {
                // Used for e.g. filelist, where there is no site selected
                // This also means that there is no "-1" (All Languages) selectable.
                $sites = $siteFinder->getAllSites();
                foreach ($sites as $site) {
                    $allSystemLanguages = $this->addSiteLanguagesToConsolidatedList(
                        $allSystemLanguages,
                        $site->getAvailableLanguages($this->getBackendUserAuthentication()),
                        $site,
                        true
                    );
                }
            } else {
                try {
                    $site = $siteFinder->getSiteByPageId((int)$pageId);
                } catch (SiteNotFoundException $e) {
                    $site = new NullSite();
                }
                $siteLanguages = $site->getAvailableLanguages($this->getBackendUserAuthentication(), true);
                if (!isset($siteLanguages[0])) {
                    $siteLanguages[0] = $site->getDefaultLanguage();
                }
                $allSystemLanguages = $this->addSiteLanguagesToConsolidatedList(
                    $allSystemLanguages,
                    $siteLanguages,
                    $site,
                    false
                );
            }

    }}

    Outside of a valid page tree, no languages are available, except if we are on page 0. Now this should probably be the same behaviour for the NullSite as well (at least IMHO, since anything else would break previous behaviour, even though the previous version was the buggy behaviour to begin with).

    As far as I can see, there is no proper way to solve this:
    • either we have code duplication, because we have to add the logic for $pageId === 0 to replace the code from the catch
    • or we use the logic from $pageId === 0 inside the catch and try to create a Site object, but then we use Exceptions to handle logic, which is a huge code smell

    I’m willing to provide a patch for both possibilities, if there is interest and this is really not the intended behaviour, if it turns out that this works as intended and my workflow is wrong, I’ll keep the patch for myself :-)

    Any thoughts?

  2. Oliver Hader changed category 10/20/21, 13:35

  3. Benni Mack commented and changed status New Needs Feedback 01/06/22, 12:19

    IMHO all pages should have a site configuration, as “0” is merely a result of things like sys_category or sys_file_metadata, which could reside on “0”. Otherwise it is much useful to exactly define the languages available for a site (= storage folder). Why? Because one might have different default language IDs for different page trees (yes, this concept existed also in prior versions and had always been a flaw). The only real solution is to define languages per page tree root.

  4. Oliver Hader commented and changed Tags pending-close 11/03/22, 12:41

    I think we can close this one, can’t we? A real solution would require a unique assignment like using locales.

  5. Georg Ringer commented and changed status Needs Feedback Closed 06/10/24, 18:15

    closing as suggested. feel free to contact me on slack if you don’t agree