Project

General

Profile

Actions

Bug #98456

closed

Slug generation for language ID -1

Added by Florian Leimer about 2 years ago. Updated 4 months ago.

Status:
Closed
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)
            )
        )
    );
}


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Bug #99529: Duplicate slugs with collisions using TCA type "slug" and records with sys_language_uid = -1Closed2023-01-12

Actions
Actions

Also available in: Atom PDF