From 8d61656c2ed47d0d4f253c0f7f0b6e8133260fa2 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 27 Apr 2009 05:58:54 +0000 Subject: [PATCH] MINOR Changed formatting and documentation for classname change detection in LeftAndMain->save(), slightly adapted to new DataObject->newClassInstance() method git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@75250 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/LeftAndMain.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/code/LeftAndMain.php b/code/LeftAndMain.php index 241f98b9..1405b5f2 100644 --- a/code/LeftAndMain.php +++ b/code/LeftAndMain.php @@ -587,10 +587,6 @@ JS; $record->Status = ($record->Status == "New page" || $record->Status == "Saved (new)") ? "Saved (new)" : "Saved (update)"; } - - - // $record->write(); - if(Director::is_ajax()) { if($SQL_id != $record->ID) { FormResponse::add("$('sitetree').setNodeIdx(\"{$SQL_id}\", \"$record->ID\");"); @@ -618,13 +614,17 @@ JS; $message = _t('LeftAndMain.SAVEDUP'); - - // Update the icon if the class has changed + // Update the class instance if necessary if($originalClass != $record->ClassName) { - $record->setClassName( $record->ClassName ); - $newClass = $record->ClassName; - $record = $record->newClassInstance( $newClass ); - + $newClassName = $record->ClassName; + // The records originally saved attribute was overwritten by $form->saveInto($record) before. + // This is necessary for newClassInstance() to work as expected, and trigger change detection + // on the ClassName attribute + $record->setClassName($originalClass); + // Replace $record with a new instance + $record = $record->newClassInstance($newClassName); + + // update the tree icon FormResponse::add("if(\$('sitetree').setNodeIcon) \$('sitetree').setNodeIcon($record->ID, '$originalClass', '$record->ClassName');"); } @@ -651,9 +651,9 @@ JS; if (isset($urlParams['publish']) && $urlParams['publish'] == 1) { $record->doPublish(); - $record->setClassName($record->ClassName); - $newClass = $record->ClassName; - $publishedRecord = $record->newClassInstance($newClass); + // Update classname with original and get new instance (see above for explanation) + $record->setClassName($originalClass); + $publishedRecord = $record->newClassInstance($record->ClassName); return $this->tellBrowserAboutPublicationChange( $publishedRecord,