How to make extbase extension recognize storage page from plugin?

13,120

Solution 1

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

Solution 2

I did a lot of research when my extension's frontend plugin (TYPO3 7.6.4) refused to use the 'pages' field of the plugin ("Record Storage Page"), so I would like to share my findings:

My extension's name is 'tx_dhsnews', my plugin's name is 'infobox'

  1. setRespectStoragePage must be set to true (default): $query->setRespectStoragePage(TRUE)

  2. In the typoscript-setup, the plugin-specific storagePid plugin.tx_dhsnews_infobox.persistence.storagePid MUST NOT be present at all! Not event with an empty value! Else the 'pages'-field will not be respected!

That's all. The Extensions Builder just created a typoscript-setup with the storagePid for the specific plugin 'infobox' set to nothing. That resulted in the plugin not respecting the 'pages' - field.

It's no problem to set the storagePid on extension-level (e.g. 'tx_dhsnews..persistence.storagePid'), the value will be merged with the value(s) given in 'pages' ("Record Storage Page"), but as soon the plugin-specific tx_[extension]_[plugin].persistence.storagePid exists in the typoscript, it will overrule everything else!

Hope this will help somebody to save some time + nerves

Solution 3

I actually modified my MVC controller to achieve a record filtering depending on the actual page(storagePid==page.id).. looked like this:

use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;

class MyMVCController extends ActionController {
protected function initializeAction() {
    parent::initializeAction();
    //fallback to current pid if no storagePid is defined
    $configuration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
    if (empty($configuration['persistence']['storagePid'])) {
        $currentPid['persistence']['storagePid'] = GeneralUtility::_GP('id');
        $this->configurationManager->setConfiguration(array_merge($configuration, $currentPid));
    }
[..]

I used the solution by http://wiki.t3easy.de/ and modified the value of the storagePid cause i developed a backend module. His tscript example didnt worked for me.. Also an article by Thomas Deuling was interesting for the topic..

but i still dont get the whole connection into my mind.. wanna go back to symfony xD

edit: for the modification of the repo queries also this article looked interesting: https://forge.typo3.org/projects/typo3v4-mvc/wiki/Default_Orderings_and_Query_Settings_in_Repository

Share:
13,120
Urs
Author by

Urs

Updated on June 30, 2022

Comments

  • Urs
    Urs almost 2 years

    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?