Commit 2485bdf5 authored by Christian Eßl's avatar Christian Eßl Committed by Daniel Goerz
Browse files

[FEATURE] Use SiteLanguageAwareInterface to check for trait existence

In AspectFactory::enrich(), the function would use class_uses() to
determine, if an aspect uses the trait SiteLanguageAwareTrait. This
however would only work on classes that use this trait, not on classes
that inherit the class with the trait (For example XClasses).
To fix this, a SiteLanguageAwareInterface was introduced, which is
checked against.

Resolves: #87380
Releases: master
Change-Id: I55e90d40ec592dc15564c49f9437e7a2640ffb0d
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61893


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
Tested-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
Reviewed-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
parent ad3267ec
...@@ -17,7 +17,7 @@ namespace TYPO3\CMS\Core\Routing\Aspect; ...@@ -17,7 +17,7 @@ namespace TYPO3\CMS\Core\Routing\Aspect;
*/ */
use TYPO3\CMS\Core\Site\Entity\SiteLanguage; use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
use TYPO3\CMS\Core\Site\SiteLanguageAwareTrait; use TYPO3\CMS\Core\Site\SiteLanguageAwareInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
/** /**
...@@ -98,8 +98,8 @@ class AspectFactory ...@@ -98,8 +98,8 @@ class AspectFactory
*/ */
protected function enrich(AspectInterface $aspect, SiteLanguage $language): AspectInterface protected function enrich(AspectInterface $aspect, SiteLanguage $language): AspectInterface
{ {
if (in_array(SiteLanguageAwareTrait::class, class_uses($aspect), true)) { // the check for the trait can be removed at any time after TYPO3 v11
/** @var $aspect SiteLanguageAwareTrait */ if ($aspect instanceof SiteLanguageAwareInterface || in_array(SiteLanguageAwareTrait::class, class_uses($aspect), true)) {
$aspect->setSiteLanguage($language); $aspect->setSiteLanguage($language);
} }
return $aspect; return $aspect;
......
...@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Core\Routing\Aspect; ...@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Core\Routing\Aspect;
* The TYPO3 project - inspiring people to share! * The TYPO3 project - inspiring people to share!
*/ */
use TYPO3\CMS\Core\Site\SiteLanguageAwareInterface;
use TYPO3\CMS\Core\Site\SiteLanguageAwareTrait; use TYPO3\CMS\Core\Site\SiteLanguageAwareTrait;
/** /**
...@@ -44,7 +45,7 @@ use TYPO3\CMS\Core\Site\SiteLanguageAwareTrait; ...@@ -44,7 +45,7 @@ use TYPO3\CMS\Core\Site\SiteLanguageAwareTrait;
* - locale: 'de_.*' * - locale: 'de_.*'
* value: 'übersicht' * value: 'übersicht'
*/ */
class LocaleModifier implements ModifiableAspectInterface class LocaleModifier implements ModifiableAspectInterface, SiteLanguageAwareInterface
{ {
use SiteLanguageAwareTrait; use SiteLanguageAwareTrait;
......
...@@ -21,6 +21,7 @@ use TYPO3\CMS\Core\Context\LanguageAspectFactory; ...@@ -21,6 +21,7 @@ use TYPO3\CMS\Core\Context\LanguageAspectFactory;
use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder; use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Domain\Repository\PageRepository; use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\Site\SiteLanguageAwareInterface;
use TYPO3\CMS\Core\Site\SiteLanguageAwareTrait; use TYPO3\CMS\Core\Site\SiteLanguageAwareTrait;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
...@@ -43,7 +44,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; ...@@ -43,7 +44,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
* routeFieldName: 'path_segment' * routeFieldName: 'path_segment'
* routeValuePrefix: '/' * routeValuePrefix: '/'
*/ */
class PersistedAliasMapper implements PersistedMappableAspectInterface, StaticMappableAspectInterface class PersistedAliasMapper implements PersistedMappableAspectInterface, StaticMappableAspectInterface, SiteLanguageAwareInterface
{ {
use SiteLanguageAwareTrait; use SiteLanguageAwareTrait;
......
...@@ -21,6 +21,7 @@ use TYPO3\CMS\Core\Context\LanguageAspectFactory; ...@@ -21,6 +21,7 @@ use TYPO3\CMS\Core\Context\LanguageAspectFactory;
use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder; use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Domain\Repository\PageRepository; use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\Site\SiteLanguageAwareInterface;
use TYPO3\CMS\Core\Site\SiteLanguageAwareTrait; use TYPO3\CMS\Core\Site\SiteLanguageAwareTrait;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
...@@ -46,7 +47,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; ...@@ -46,7 +47,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
* *
* @internal might change its options in the future, be aware that there might be modifications. * @internal might change its options in the future, be aware that there might be modifications.
*/ */
class PersistedPatternMapper implements PersistedMappableAspectInterface, StaticMappableAspectInterface class PersistedPatternMapper implements PersistedMappableAspectInterface, StaticMappableAspectInterface, SiteLanguageAwareInterface
{ {
use SiteLanguageAwareTrait; use SiteLanguageAwareTrait;
......
...@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Core\Routing\Aspect; ...@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Core\Routing\Aspect;
* The TYPO3 project - inspiring people to share! * The TYPO3 project - inspiring people to share!
*/ */
use TYPO3\CMS\Core\Site\SiteLanguageAwareInterface;
use TYPO3\CMS\Core\Site\SiteLanguageAwareTrait; use TYPO3\CMS\Core\Site\SiteLanguageAwareTrait;
/** /**
...@@ -37,7 +38,7 @@ use TYPO3\CMS\Core\Site\SiteLanguageAwareTrait; ...@@ -37,7 +38,7 @@ use TYPO3\CMS\Core\Site\SiteLanguageAwareTrait;
* 2k18: '2018' * 2k18: '2018'
* next: '2019' * next: '2019'
*/ */
class StaticValueMapper implements StaticMappableAspectInterface, \Countable class StaticValueMapper implements StaticMappableAspectInterface, SiteLanguageAwareInterface, \Countable
{ {
use SiteLanguageAwareTrait; use SiteLanguageAwareTrait;
......
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Core\Site;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* Interface for SiteLanguageAware features of TYPO3
*/
interface SiteLanguageAwareInterface
{
/**
* @param Entity\SiteLanguage $siteLanguage
*/
public function setSiteLanguage(Entity\SiteLanguage $siteLanguage);
/**
* @return Entity\SiteLanguage
*/
public function getSiteLanguage(): Entity\SiteLanguage;
}
.. include:: ../../Includes.txt
========================================================================================
Feature: #87380 - Introduce SiteLanguageAwareInterface to denote site language awareness
========================================================================================
See :issue:`87380`
Description
===========
A `SiteLanguageAwareInterface` with the methods `setSiteLanguage(Entity\SiteLanguage $siteLanguage)`
and `getSiteLanguage()` has been introduced. The interface can be used to denote a class as aware of
the site language.
Impact
======
Routing aspects respecting the site language are now using the `SiteLanguageAwareInterface` in addition
to the `SiteLanguageAwareTrait`. The `AspectFactory` check has been adjusted to check for the interface
_or_ the trait. If you are currently using the trait, you should implement the interface as well.
.. index:: PHP-API, ext:core
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment