phptypo3extbasetypo3-6.1.x

How to make extbase extension recognize storage page from plugin?


In an extbase extension built with extension builder on TYPO3 6.1.7, I haven't set any storagePid via Typoscript.

But I have set the "Record Storage Page" in the plugin:

enter image description here

I would expect that it would now only fetch records from this page. But it doesn't, it just returns all items from that table.

How do I make the extension recognize the setting from the plugin? Or (if it's supposed to do that out of the box) how do I find out why it doesn't?


Solution

  • Add the following code to your repository

    namespace <Vendor>\<Extkey>\Domain\Repository;
    
    class ExampleRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
    
        // Example for repository wide settings
        public function initializeObject() {
            /** @var $defaultQuerySettings \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings */
            $defaultQuerySettings = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings');
            // add the pid constraint
            $defaultQuerySettings->setRespectStoragePage(TRUE);
    }
    
        // Example for a function setup changing query settings
        public function findSomething() {
            $query = $this->createQuery();
            // add the pid constraint
            $query->getQuerySettings()->setRespectStoragePage(TRUE);
            // the same functions as shown in initializeObject can be applied.
            return $query->execute();
        }
    }
    

    You will find more informations at this page http://forge.typo3.org/projects/typo3v4-mvc/wiki/Default_Orderings_and_Query_Settings_in_Repository