Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EXTBASE: How to get hidden record

How to get hidden record in frontend? Want to get hidden record then change hidden to 0.

like image 787
gSorry Avatar asked Dec 07 '22 05:12

gSorry


1 Answers

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);
    }
}
like image 75
nito Avatar answered Dec 18 '22 14:12

nito