How to get hidden record in frontend? Want to get hidden record then change hidden to 0.
Your can make this settings for a singe method in your Repository:
namespace Vendor\ExtensionName\Domain\Repository;
use TYPO3\CMS\Extbase\Persistence\Repository;
/**
* Some Repository
*/
class SomeRepository extends Repository
{
/**
* Find a record by uid even if it is hidden or deleted
*
* @param int $uid
* @return Some
*/
public function findHiddenByUid($uid): Some
{
$query = $this->createQuery();
// Here you enable the hidden and deleted Records
$query->getQuerySettings()
->setIgnoreEnableFields(true)
->setIncludeDeleted(true);
// Your query
$query->matching($query->equals('uid', $uid));
return $query->execute()->getFirst();
}
}
Or for the entire Repository. This includes the methods that you inherit from TYPO3\CMS\Extbase\Persistence\Repository
:
namespace Vendor\ExtensionName\Domain\Repository;
use TYPO3\CMS\Extbase\Persistence\Repository;
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
/**
* Some Repository
*/
class SomeRepository extends Repository
{
/**
* Always return hidden and deleted records from this Repository
*/
public function initializeObject(): void
{
// Load the querySettings
$querySettings = $this->objectManager->get(Typo3QuerySettings::class);
// Ignore hidden and deleted records
$querySettings
->setIgnoreEnableFields(true)
->setIncludeDeleted(true);
// Set your settings as default for the entire Repository
$this->setDefaultQuerySettings($querySettings);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With