EXTBASE:如何获取隐藏记录

问题描述 投票:3回答:3

如何在前端获取隐藏记录?想要隐藏记录然后将隐藏更改为0。

repository typo3 hidden-field extbase
3个回答
8
投票

您可以在存储库中为单个方法进行此设置:

<?php
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 object
     */
    public function findHiddenByUid($uid) {
        $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继承的方法:

<?php
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() {
        // 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);
    }
}

3
投票

关键是在'querySettings'中禁用'respectEnableFields'属性。您可以在您的存储库中执行此操作:

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();
    }
}

3
投票

您可以使用存储库的initializeObject方法,因此我们不必为存储库中的每个方法编写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);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.