/** * Initializes PID detector */ protected function initPidDetector() { if ($this->respectPidDetector) { $PIDs = $this->pidDetector->getPids(); if (!$PIDs) { // throw new Exception('It was not possible to determine any page IDs to get records from. Please configure your plugin correctly.', 1331382978); } if ($this->defaultQuerySettings === NULL) { $this->defaultQuerySettings = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings'); } $this->defaultQuerySettings->setRespectStoragePage(TRUE); $this->defaultQuerySettings->setStoragePageIds($PIDs); } }
/** @test */ public function getPidsReturnsCorrectPidsForManualMode() { $testArray = array(1, 2, 3, 4); $pidDetector = new Tx_Yag_Utility_PidDetector(Tx_Yag_Utility_PidDetector::MANUAL_MODE); $pidDetector->setPids($testArray); $this->assertEquals($testArray, $pidDetector->getPids()); }
/** * Determine the storage page ID for a given NEW record * * This does the following: * - If there is a TypoScript configuration "classes.CLASSNAME.newRecordStoragePid", that is used to store new records. * - If there is no such TypoScript configuration, it uses the first value of The "storagePid" taken for reading records. * * @param \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object * @return int the storage Page ID where the object should be stored */ protected function determineStoragePageIdForNewRecord(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object = null) { $pids = null; /** * What happens here? * * We globally overwrite implementation of backend class (this class). * This means that all other Extbase plugins that are probably inserted on the * same page would also use this backend class. * * So we give the yag domain models an interface which we check here and use * pid detection only, if we get a new objecte that implements this interface. * All other objects will be handled the default way. */ if (is_a($object, 'Tx_Yag_Domain_Model_DomainModelInterface')) { $pids = $this->pidDetector->getPids(); } if (!empty($pids) && count($pids) > 0) { return $pids[0] == -1 ? 0 : $pids[0]; } else { return parent::determineStoragePageIdForNewRecord($object); } }
/** * Initializes the view before invoking an action method. * * Override this method to solve assign variables common for all actions * or prepare the view in another way before the action is called. * * @param \TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view The view to be initialized * @return void * @api */ protected function initializeView(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view) { if (method_exists($view, 'injectConfigurationBuilder')) { $view->setConfigurationBuilder($this->configurationBuilder); } $this->setCustomPathsInView($view); if ($this->yagContext !== null) { $this->yagContext->injectControllerContext($this->controllerContext); } $this->view->assign('config', $this->configurationBuilder); $this->view->assign('yagContext', $this->yagContext); $this->view->assign('currentPid', current($this->pidDetector->getPids())); }