mirror of
https://github.com/FriendsOfTYPO3/tea.git
synced 2024-11-25 06:56:12 +01:00
[BUGFIX] Configure DI and avoid using ObjectManager
in TYPO3 11LTS (#399)
`ObjectManager` is deprecated in V11. Fixes #387
This commit is contained in:
parent
934f43572f
commit
a1a84a511f
3 changed files with 31 additions and 5 deletions
|
@ -14,10 +14,20 @@ use TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface;
|
|||
*/
|
||||
trait StoragePageAgnosticTrait
|
||||
{
|
||||
/**
|
||||
* @var QuerySettingsInterface
|
||||
*/
|
||||
private $querySettings;
|
||||
|
||||
public function injectQuerySettings(QuerySettingsInterface $querySettings): void
|
||||
{
|
||||
$this->querySettings = $querySettings;
|
||||
}
|
||||
|
||||
public function initializeObject(): void
|
||||
{
|
||||
/** @var QuerySettingsInterface $querySettings */
|
||||
$querySettings = $this->objectManager->get(QuerySettingsInterface::class);
|
||||
$querySettings = clone $this->querySettings;
|
||||
|
||||
$querySettings->setRespectStoragePage(false);
|
||||
$this->setDefaultQuerySettings($querySettings);
|
||||
}
|
||||
|
|
9
Configuration/Services.yaml
Normal file
9
Configuration/Services.yaml
Normal file
|
@ -0,0 +1,9 @@
|
|||
services:
|
||||
_defaults:
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
public: false
|
||||
|
||||
TTN\Tea\:
|
||||
resource: '../Classes/*'
|
||||
exclude: '../Classes/Domain/Model/*'
|
|
@ -6,6 +6,7 @@ namespace TTN\Tea\Tests\Functional\Domain\Repository\Product;
|
|||
|
||||
use TTN\Tea\Domain\Model\Product\Tea;
|
||||
use TTN\Tea\Domain\Repository\Product\TeaRepository;
|
||||
use TYPO3\CMS\Core\Information\Typo3Version;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
|
||||
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
||||
|
@ -38,9 +39,15 @@ class TeaRepositoryTest extends FunctionalTestCase
|
|||
|
||||
$this->persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class);
|
||||
|
||||
/** @var ObjectManager $objectManager */
|
||||
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
|
||||
$this->subject = $objectManager->get(TeaRepository::class);
|
||||
/** @var Typo3Version $versionInformation */
|
||||
$versionInformation = GeneralUtility::makeInstance(Typo3Version::class);
|
||||
if ($versionInformation->getMajorVersion() >= 11) {
|
||||
$this->subject = $this->getContainer()->get(TeaRepository::class);
|
||||
} else {
|
||||
/** @var ObjectManager $objectManager */
|
||||
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
|
||||
$this->subject = $objectManager->get(TeaRepository::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue