如何在前端获取隐藏的记录?想要获取隐藏的记录,则需要将 hidden 改为 0。
您可以在您的 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();
}
}
或者针对整个存储库进行操作。这包括您从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);
}
}
class SomeRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
/**
* initialize querySettings
*/
public function initializeObject() {
$querySettings = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings');
// Get Hidden and Deleted Records
$querySettings->getQuerySettings()->setIgnoreEnableFields(true);
//Disable Storage pid
$querySettings->setRespectStoragePage(FALSE);
$this->setDefaultQuerySettings($querySettings);
}
}
class SomeRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
public function findHiddenByUid($uid) {
$query = $this->createQuery();
$query->getQuerySettings()->setRespectEnableFields(FALSE);
$query->matching($query->equals('uid', $uid));
return $query->execute()->getFirst();
}
}
setIgnoreEnableFields(TRUE)
。setRespectEnableFields
已被弃用并从 TYPO3 6.2.0 中删除。 - Charles Brunet
$querySettings->getQuerySettings()->setIgnoreEnableFields(true)
doesn't work, just use$querySettings->setIgnoreEnableFields(true)
- andreas