[TYPO3-mvc] different storagePid and newRecordStoragePid for each model

typo3 at litedesigns.nl typo3 at litedesigns.nl
Thu Mar 8 14:34:21 CET 2012


Hi list,

I have a question about setting different storagePid and
newRecordStoragePid for each of my models. I want these to be used in the
Frontend and in the Backend. I want to use a separate sysFolder to store /
read my objects to / from.
Simply put i have two models: Company > 1:n > Departments. In my TCA for
Company i have setup an 'inline' relation to be able to add new
Departments in the Backend when editing my Company.

By browsing the mailing list i have found this solution:

With TSConfig i can define in which sysFolder the new Company and
Department are stored from the Backend by using:
TCAdefaults.tx_myext_domain_model_company.pid = 16
TCAdefaults.tx_myext_domain_model_department.pid = 17

For my Frontend plugin to read the Companies and Departments from the
correct sysFolders i can use this typoscript:
plugin.tx_myext.persistence.storagePid = 16,17

For my Frontend plugin to create a new Company or Department in the
correct sysFolder i can use this typoscript:
plugin.tx_myext.persistence.classes.Tx_MyExt_Domain_Model_Company.newRecordStoragePid
= 16
plugin.tx_myext.persistence.classes.Tx_MyExt_Domain_Model_Department.newRecordStoragePid
= 17

All these settings work fine, my Companies and Departments are read /
written to / from the correct sysFolders in both the Frontend and the
Backend, even when inline adding a Department to a Company. But apart from
using constants for the typoscript parts (instead of hardcoding as above)
i feel this is not very flexible for my client and the pid's need to be
defined 3 times! Most likely the sysFolders will never need to be changed,
but if possible i would still like to know if there is a more flexible
solution which does not need my client to edit the template constants and
TSConfig.

For the Frontend i could add a Flexform to my plugin instances defining
the sysFolder to use. In my repositories i could overwrite the
createQuery() function like this:
/**
 * Returns a query for objects of this repository
 *
 * @return Tx_Extbase_Persistence_QueryInterface
 * @api
 */
/*
public function createQuery()
{
	$query = parent::createQuery();
	$querySettings = $query->getQuerySettings();

	$configManager =
$this->objectManager->get('Tx_Extbase_Configuration_ConfigurationManager');
	$frameworkConfiguration =
$configManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);

	if ($frameworkConfiguration['settings']['pages'])
	{
		// read settings.pages from flexform if it exists and overwrite the
storagePid
		$querySettings->setStoragePageIds(t3lib_div::intExplode(',',
$frameworkConfiguration['settings']['pages']));
		$query->setQuerySettings($querySettings);
	}

	return $query;
}

And the flexform <el> snippet:
<settings.pages>
	<TCEforms>
		<exclude>1</exclude>
		<label>Select sysFolder with the Companies:</label>
		<config>
			<type>group</type>
			<internal_type>db</internal_type>
			<allowed>pages</allowed>
			<size>1</size>
			<maxitems>1</maxitems>
			<minitems>0</minitems>
			<show_thumbs>1</show_thumbs>
		</config>
	</TCEforms>
</settings.pages>

And then in my Controller createActions i can set this:
$newCompany->setPid($this->settings['pages']);
Or
$newDepartment->setPid($this->settings['pages']);
right before adding the new object to the repository.

For the Frontend i have now completely removed all the need for typoscript
and TSConfig settings and the sysFolders can be selected in the plugin
instances flexforms, which is much more intuitive for my client.

But this does not make sense for the Backend (even if i would know how to
read and set the sysFolder value) since there can be more then one plugin
instance, each with a different sysFolder set. So the Backend has no way
of knowing where to store the new objects.

So is there a way (could be by writing a Backend plugin for configuring my
sysFolders) so that both the Frontend and Backend use the same sysFolders
for reading and writing my objects? And in the backend this also needs to
work when 'inline adding a new Department' from within the Company.

I'm just looking for some tips which way i should go, not a complete
codelisting or something. Although the latter is no problem of course :)

Kind regards,
Tim






More information about the TYPO3-project-typo3v4mvc mailing list