Bug #89295
closedTypo3QuerySettings set as DefaultQuerySettings in a Repositories initializeObject Method are not honored
100%
Description
The premise is that an Extbase Repository has been extended from Repository, and the initializeObject Method is used to set Typo3QuerySettings and stored in $this->setDefaultQuerySettings, for example like this:
class EventRepository extends Repository { public function initializeObject() { $querySettings = $this->objectManager->get(Typo3QuerySettings::class); $context = GeneralUtility::makeInstance(Context::class); $querySettings->setLanguageUid($context->getPropertyFromAspect('language','id')); $querySettings->setLanguageOverlayMode(1); $this->setDefaultQuerySettings($querySettings); } }
The reason why we set for example the language like this has a different issue, which will be a different bug report. This is just an example.
The expected behaviour now is that any method using $this->createQuery(), including the magic findX methods and findAll will now use these settings.
This does not happen as in Generic\QueryFactory->create a new DefaultQuery is generated.
public function create($className) { $query = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\QueryInterface::class, $className); $querySettings = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface::class);
This has several side effects. Parts of 'our' defaultQuerySettings are used, parts of the new one are used. And anything related to the storagePageIds will fail (no storagePageId will be set in the querySettings, not from typoscript or the the pages field or flexform)
We patched in our project the call-chain down to Generic\QueryFactory->create so the repositories defaultQuerySettings will be passed through the instances and if not null will be used instead if a new instance.
The patch is attached.
The System behaves as expected after that, honoring the settings set in a initializeObject method, even for the magic Methods
Files