Project

General

Profile

Actions

Bug #98456

open

Slug generation for language ID -1

Added by Florian Leimer over 1 year ago. Updated over 1 year ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
DataHandler aka TCEmain
Start date:
2022-09-28
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
10
PHP Version:
7.4
Tags:
slug
Complexity:
easy
Is Regression:
Sprint Focus:

Description

When creating an unique slug the language id is considered. At the moment there isn't any logic for the language id "-1" (all languages) and it is treated like any other language. This is a problem because it is possible that a record with a specific language and one with "all languages" can have the same slug.
I encountered this problem with EXT:news, where the routing wasn't able to get the correct uid.

My fix in \TYPO3\CMS\Core\DataHandling\SlugHelper:

/**
 * @param QueryBuilder $queryBuilder
 * @param int $languageId
 */
protected function applyLanguageConstraint(QueryBuilder $queryBuilder, int $languageId)
{
    $languageFieldName = $GLOBALS['TCA'][$this->tableName]['ctrl']['languageField'] ?? null;
    if (!is_string($languageFieldName)) {
        return;
    }

    if ($languageId === -1) {
        return;
    }

    // Only check records of the given language
    $queryBuilder->andWhere(
        $queryBuilder->expr()->orX(
            $queryBuilder->expr()->eq(
                $languageFieldName,
                $queryBuilder->createNamedParameter($languageId, \PDO::PARAM_INT)
            ),
            $queryBuilder->expr()->eq(
                $languageFieldName,
                $queryBuilder->createNamedParameter(-1, \PDO::PARAM_INT)
            )
        )
    );
}

Actions

Also available in: Atom PDF