I created an extension using Extension Builder, and included a backend module, under the web section. In the generated code, there are two constants for the storage pid: one for plugins and one for modules.
Now I like my module to use the storage pid from the selected page or folder in the pagetree, like page, list, or template modules do. How can I use storage pid from pagetree instead of using a constant, in a backend module?
To get the selected page from the page tree in your backend module, one way is to simply get the id
param, ideally in your initializer.
Since extbase reads the storage pid from your module (or plugin for the frontend) settings, you can just override the storagePid
part so you don't have to set the pid for each query / otherwise in your repositories.
The following should work. However, I use this in a CommandController and not in a controller used in the backend. I hadn't to change anything there because the repositories automatically scoped records to the selected page.
class Tx_MyExt_Controller_BackendController extends Tx_Extbase_MVC_Controller_ActionController {
/**
* @var Tx_Extbase_Configuration_ConfigurationManagerInterface
* @inject
*/
protected $configurationManager;
/**
* @var int Current page
*/
protected $pageId;
/**
* Action initializer
*
* @return void
*/
protected function initializeAction()
{
$this->pageId = (int)t3lib_div::_GP('id');
$frameworkConfiguration = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
$persistenceConfiguration = array('persistence' => array('storagePid' => $this->pageId));
$this->configurationManager->setConfiguration(array_merge($frameworkConfiguration, $persistenceConfiguration));
}
}