TYPO3 Domain Repository Temporarily Change Settings
Normally if someone wants to run the function findAll()
, he/she has to define the persistence Pid to let TYPO3 know where to look. If the persistence pid is not present, a function in the repository would do the trick. Like the following:
public function initializeObject() {
$querySettings = $this->objectManager->get(Typo3QuerySettings::class);
$querySettings->setRespectStoragePage(false);
$this->setDefaultQuerySettings($querySettings);
}
But what happens if we do not have access to the repository? I mean the repository belongs to another extension and you can not edit it. The solution would be to extend the repository to an extend extension but this is sometimes too much to create an extended version only for that.
The question here is:
How do i temporarily, just for this request, change the settings of the repository, in this case change the setRespectStoragePage
to false
.
Answer
After some coding i finally figured it out.
Step 1.
create a protected variable where you wanna use the repository request:
/**
* @var \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
*/
protected $querySettings;
Step 2.
Inject the QuerySettingsInterface
in your current PHP class. If you want to use that in your controller, then you could do something like that:
public function __construct()
{
parent::__contruct();
$this->querySettings = $this->objectManager->get(QuerySettingsInterface::class);
}
otherwise
public function __construct()
{
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->querySettings = $objectManager->get(QuerySettingsInterface::class);
}
Step 3
Finally you can set the settings like that:
$this->querySettings->setRespectStoragePage(false);
$this->contactRepository->setDefaultQuerySettings($this->querySettings);
$contacts = $this->contactRepository->findAll();
Simple and no extended extension needed just to implement the function in the repository.
Best regards
Related Questions
- → Prevent form action from being followed by robots
- → Render Link within Typoscript Controller
- → How can I implement the sitemaps for a TYPO3 Multidomainsystem when i have only one root folder?
- → TYPO3 - Overriding & adding meta tags (from tx_metaseo) on detail view of custom extension
- → How can i remove the region in TYPO3 9 SEO extension from hreflang
- → generate SEO sitemap for tt_address in TYPO3 and how to beautify with slugs
- → TYPO3 and IOS: can't open the page
- → TYPO3: How do i render tt_content text elements in my own extensions?
- → TYPO3 News Sitemap Configuration - actual date in additionalWhere statement
- → Check the Database of a typo3-Website
- → How to create a record and add an image in database in TYPO3
- → TYPO3 Frontent: Form Action results Page not found
- → RealURL with GET parameters