Merge pull request #5103 from hailwood/patch-3

API Populate foreign key before getting CMS fields
This commit is contained in:
Damian Mooyman 2016-03-01 15:43:08 +13:00
commit 2e856e6315

View File

@ -385,20 +385,22 @@ class GridFieldDetailForm_ItemRequest extends RequestHandler {
$actions->push(new LiteralField('cancelbutton', $text));
}
}
// If we are creating a new record in a has-many list, then
// pre-populate the record's foreign key.
if($list instanceof HasManyList && !$this->record->isInDB()) {
$key = $list->getForeignKey();
$id = $list->getForeignID();
$this->record->$key = $id;
}
$fields = $this->component->getFields();
if(!$fields) $fields = $this->record->getCMSFields();
// If we are creating a new record in a has-many list, then
// pre-populate the record's foreign key. Also disable the form field as
// it has no effect.
// Disable the form field as it has no effect.
if($list instanceof HasManyList) {
$key = $list->getForeignKey();
$id = $list->getForeignID();
if(!$this->record->isInDB()) {
$this->record->$key = $id;
}
if($field = $fields->dataFieldByName($key)) {
$fields->makeFieldReadonly($field);