[+FEATURE] Extbase (Persistence): Allow pid of object to be set from action-controller
authorStefan Neufeind <typo3.neufeind@speedpartner.de>
Fri, 10 Jun 2011 19:51:28 +0000 (21:51 +0200)
committerSebastian Kurfuerst <sebastian@typo3.org>
Mon, 1 Aug 2011 12:37:52 +0000 (14:37 +0200)
If pid of an object is set then
Tx_Extbase_Persistence_Backend->determineStoragePageIdForNewRecord()
needs to give it priority.

Thanks to Michael Budnick and Balisky Christophe.

Change-Id: Ib99400eb6947044dd190d47de5dce0c63444bb20
Resolves: #7572

typo3/sysext/extbase/Classes/Persistence/Backend.php

index f6eca1d..4b98289 100644 (file)
@@ -853,6 +853,7 @@ class Tx_Extbase_Persistence_Backend implements Tx_Extbase_Persistence_BackendIn
         * Determine the storage page ID for a given NEW record
         *
         * This does the following:
+        * - If the domain object has an accessible property 'pid' (i.e. through a getPid() method), that is used to store the record.
         * - 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.
         *
@@ -862,6 +863,12 @@ class Tx_Extbase_Persistence_Backend implements Tx_Extbase_Persistence_BackendIn
        protected function determineStoragePageIdForNewRecord(Tx_Extbase_DomainObject_DomainObjectInterface $object = NULL) {
                $frameworkConfiguration = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
                if ($object !== NULL) {
+                       if (Tx_Extbase_Reflection_ObjectAccess::isPropertyGettable($object, 'pid')) {
+                               $pid = Tx_Extbase_Reflection_ObjectAccess::getProperty($object, 'pid');
+                               if (isset($pid)) {
+                                       return (int)$pid;
+                               }
+                       }
                        $className = get_class($object);
                        if (isset($frameworkConfiguration['persistence']['classes'][$className]) && !empty($frameworkConfiguration['persistence']['classes'][$className]['newRecordStoragePid'])) {
                                return (int)$frameworkConfiguration['persistence']['classes'][$className]['newRecordStoragePid'];