mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
BUGFIX MemberTableField_Popup had an odd way of overloading saveComplexTableField() - this should be on MemberTableField instead, since that's the direct subclass of ComplexTableField for where saveComplexTableField() is defined. This broke the "Add Member" button in CMS Security, probably due to the way the form URLs have been changed. See ticket #2907 for the reported problem.
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@63828 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
1034826574
commit
a0c107a338
@ -299,6 +299,35 @@ class MemberTableField extends ComplexTableField {
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Same behaviour as parent class, but adds the
|
||||
* member to the passed GroupID.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function saveComplexTableField($data, $form, $params) {
|
||||
$className = $this->sourceClass();
|
||||
$childData = new $className();
|
||||
$form->saveInto($childData);
|
||||
$childData->write();
|
||||
|
||||
$childData->Groups()->add($data['GroupID']);
|
||||
|
||||
$closeLink = sprintf(
|
||||
'<small><a href="' . $_SERVER['HTTP_REFERER'] . '" onclick="javascript:window.top.GB_hide(); return false;">(%s)</a></small>',
|
||||
_t('ComplexTableField.CLOSEPOPUP', 'Close Popup')
|
||||
);
|
||||
$message = sprintf(
|
||||
_t('ComplexTableField.SUCCESSADD', 'Added %s %s %s'),
|
||||
$childData->singular_name(),
|
||||
'<a href="' . $this->Link() . '">' . $childData->Title . '</a>',
|
||||
$closeLink
|
||||
);
|
||||
$form->sessionMessage($message, 'good');
|
||||
|
||||
Director::redirectBack();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cached version for getting the appropraite members for this particular group.
|
||||
*
|
||||
@ -361,54 +390,6 @@ class MemberTableField_Popup extends ComplexTableField_Popup {
|
||||
Requirements::javascript(CMS_DIR . '/javascript/MemberTableField_popup.js');
|
||||
}
|
||||
|
||||
/**
|
||||
* Same behaviour as parent class, but adds the member to the passed GroupID.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function saveComplexTableField() {
|
||||
$id = (isset($_REQUEST['ctf']['childID'])) ? Convert::raw2sql($_REQUEST['ctf']['childID']) : false;
|
||||
|
||||
if (is_numeric($id) && $id != 0) {
|
||||
$childObject = DataObject::get_by_id($this->sourceClass, $id);
|
||||
} else {
|
||||
$childObject = new $this->sourceClass();
|
||||
$this->fields->removeByName('ID');
|
||||
}
|
||||
|
||||
$this->saveInto($childObject);
|
||||
|
||||
$form = $this->controller->DetailForm($childObject->ID);
|
||||
|
||||
$valid = $childObject->validate();
|
||||
if($valid->valid()) {
|
||||
$childObject->write();
|
||||
|
||||
// custom behaviour for MemberTableField: add member to current group
|
||||
$childObject->Groups()->add($_REQUEST['GroupID']);
|
||||
|
||||
$form->sessionMessage("Changes saved.", 'good');
|
||||
} else {
|
||||
$form->sessionMessage(Convert::raw2xml("I couldn't save your changes:\n\n" . $valid->starredList()), 'bad');
|
||||
}
|
||||
|
||||
|
||||
// if ajax-call in an iframe, update window
|
||||
if(Director::is_ajax()) {
|
||||
// Newly saved objects need their ID reflected in the reloaded form to avoid double saving
|
||||
$form->loadDataFrom($childObject);
|
||||
|
||||
if($valid->valid()) {
|
||||
FormResponse::update_dom_id($form->FormName(), $form->formHtmlContent(), true, 'update');
|
||||
} else {
|
||||
FormResponse::load_form($form->forTemplate(), $form->FormName());
|
||||
}
|
||||
|
||||
return FormResponse::respond();
|
||||
} else {
|
||||
Director::redirectBack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MemberTableField_ItemRequest extends ComplexTableField_ItemRequest {
|
||||
|
Loading…
Reference in New Issue
Block a user