Merge pull request #1718 from chillu/pulls/member-group-nested-editing

FIX Disallow group removal when member is edited in groups view
This commit is contained in:
Sam Minnée 2013-04-08 15:15:47 -07:00
commit 322b00ece0

View File

@ -102,12 +102,18 @@ class Group extends DataObject {
$config->getComponentByType('GridFieldDetailForm')
->setValidator(new Member_Validator())
->setItemEditFormCallback(function($form, $component) use($group) {
$record = $form->getRecord();
$groupsField = $form->Fields()->dataFieldByName('DirectGroups');
if($groupsField) {
// If new records are created in a group context,
// set this group by default.
$record = $form->getRecord();
if($record && !$record->ID) {
$groupsField = $form->Fields()->dataFieldByName('DirectGroups');
if($groupsField) $groupsField->setValue($group->ID);
$groupsField->setValue($group->ID);
} elseif($record && $record->ID) {
// TODO Mark disabled once chosen.js supports it
// $groupsField->setDisabledItems(array($group->ID));
$form->Fields()->replaceField('DirectGroups', $groupsField->performReadonlyTransformation());
}
}
});
$memberList = GridField::create('Members',false, $this->Members(), $config)->addExtraClass('members_grid');