mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT Prepopulating group on new members (fixes #7217)
This commit is contained in:
parent
72eadef113
commit
f873707e9d
@ -149,14 +149,14 @@ class GridFieldDetailForm implements GridField_URLHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param function $cb Make changes on the edit form after constructing it.
|
||||
* @param Closure $cb Make changes on the edit form after constructing it.
|
||||
*/
|
||||
public function setItemEditFormCallback($cb) {
|
||||
public function setItemEditFormCallback(Closure $cb) {
|
||||
$this->itemEditFormCallback = $cb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return function
|
||||
* @return Closure
|
||||
*/
|
||||
public function getItemEditFormCallback() {
|
||||
return $this->itemEditFormCallback;
|
||||
|
@ -94,12 +94,23 @@ class Group extends DataObject {
|
||||
$permissionsField->setHiddenPermissions(SecurityAdmin::$hidden_permissions);
|
||||
|
||||
if($this->ID) {
|
||||
$group = $this;
|
||||
$config = new GridFieldConfig_RelationEditor();
|
||||
$config->addComponents(new GridFieldExportButton('before'));
|
||||
$config->addComponents(new GridFieldPrintButton('before'));
|
||||
$config->getComponentByType('GridFieldAddExistingAutocompleter')
|
||||
->setResultsFormat('$Title ($Email)')->setSearchFields(array('FirstName', 'Surname', 'Email'));
|
||||
$config->getComponentByType('GridFieldDetailForm')->setValidator(new Member_Validator());
|
||||
$config->getComponentByType('GridFieldDetailForm')
|
||||
->setValidator(new Member_Validator())
|
||||
->setItemEditFormCallback(function($form, $component) use($group) {
|
||||
// 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);
|
||||
}
|
||||
});
|
||||
$memberList = GridField::create('Members',false, $this->Members(), $config)->addExtraClass('members_grid');
|
||||
// @todo Implement permission checking on GridField
|
||||
//$memberList->setPermissions(array('edit', 'delete', 'export', 'add', 'inlineadd'));
|
||||
|
Loading…
Reference in New Issue
Block a user