mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-09-06 01:31:09 +02:00
BUGFIX Fixed saving of widgets correctly if ID is not numeric
MINOR Code formatting fixes git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@76186 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
0edf8eb19b
commit
892849c0e1
@ -45,10 +45,9 @@ class WidgetAreaEditor extends FormField {
|
|||||||
$name = $this->name;
|
$name = $this->name;
|
||||||
$idName = $name . "ID";
|
$idName = $name . "ID";
|
||||||
|
|
||||||
|
|
||||||
$widgetarea = $record->$name();
|
$widgetarea = $record->$name();
|
||||||
|
|
||||||
$widgetarea->write();
|
$widgetarea->write();
|
||||||
|
|
||||||
$record->$idName = $widgetarea->ID;
|
$record->$idName = $widgetarea->ID;
|
||||||
|
|
||||||
$widgets = $widgetarea->Widgets();
|
$widgets = $widgetarea->Widgets();
|
||||||
@ -57,22 +56,32 @@ class WidgetAreaEditor extends FormField {
|
|||||||
// alternatively, we could delete all the fields and re add them
|
// alternatively, we could delete all the fields and re add them
|
||||||
$missingWidgets = array();
|
$missingWidgets = array();
|
||||||
|
|
||||||
|
if($widgets) {
|
||||||
foreach($widgets as $existingWidget) {
|
foreach($widgets as $existingWidget) {
|
||||||
$missingWidgets[$existingWidget->ID] = $existingWidget;
|
$missingWidgets[$existingWidget->ID] = $existingWidget;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// write the new widgets to the database
|
// write the new widgets to the database
|
||||||
if(isset($_REQUEST['Widget'])) {
|
if(isset($_REQUEST['Widget'])) {
|
||||||
|
|
||||||
foreach(array_keys($_REQUEST['Widget']) as $newWidgetID) {
|
foreach(array_keys($_REQUEST['Widget']) as $newWidgetID) {
|
||||||
$newWidgetData = $_REQUEST['Widget'][$newWidgetID];
|
$newWidgetData = $_REQUEST['Widget'][$newWidgetID];
|
||||||
|
|
||||||
// \"ParentID\"=0 is for the new page
|
// Sometimes the id is "new-1" or similar, ensure this doesn't get into the query
|
||||||
$widget = DataObject::get_one( 'Widget', "(\"ParentID\"='{$record->$name()->ID}' OR \"ParentID\"=0) AND \"Widget\".\"ID\"='$newWidgetID'" );
|
if(!is_numeric($newWidgetID)) {
|
||||||
|
$newWidgetID = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// \"ParentID\" = '0' is for the new page
|
||||||
|
$widget = DataObject::get_one(
|
||||||
|
'Widget',
|
||||||
|
"(\"ParentID\" = '{$record->$name()->ID}' OR \"ParentID\" = '0') AND \"Widget\".\"ID\" = '$newWidgetID'"
|
||||||
|
);
|
||||||
|
|
||||||
// check if we are updating an existing widget
|
// check if we are updating an existing widget
|
||||||
if($widget && isset($missingWidgets[$widget->ID]))
|
if($widget && isset($missingWidgets[$widget->ID])) {
|
||||||
unset($missingWidgets[$widget->ID]);
|
unset($missingWidgets[$widget->ID]);
|
||||||
|
}
|
||||||
|
|
||||||
// create a new object
|
// create a new object
|
||||||
if(!$widget && !empty($newWidgetData['Type']) && class_exists($newWidgetData['Type'])) {
|
if(!$widget && !empty($newWidgetData['Type']) && class_exists($newWidgetData['Type'])) {
|
||||||
@ -89,17 +98,18 @@ class WidgetAreaEditor extends FormField {
|
|||||||
if($widget->ParentID == 0) {
|
if($widget->ParentID == 0) {
|
||||||
$widget->ParentID = $record->$name()->ID;
|
$widget->ParentID = $record->$name()->ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
$widget->populateFromPostData($newWidgetData);
|
$widget->populateFromPostData($newWidgetData);
|
||||||
//$editable->write();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove the fields not saved
|
// remove the fields not saved
|
||||||
|
if($missingWidgets) {
|
||||||
foreach($missingWidgets as $removedWidget) {
|
foreach($missingWidgets as $removedWidget) {
|
||||||
if(isset($removedWidget) && is_numeric($removedWidget->ID)) $removedWidget->delete();
|
if(isset($removedWidget) && is_numeric($removedWidget->ID)) $removedWidget->delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
Loading…
Reference in New Issue
Block a user