Skip to content

Commit

Permalink
FIX Add polymorphic class on new records for use in forms.
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed May 2, 2022
1 parent 2836478 commit 95ede91
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Forms/GridField/GridFieldDetailForm_ItemRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\ORM\HasManyList;
use SilverStripe\ORM\ManyManyList;
use SilverStripe\ORM\PolymorphicHasManyList;
use SilverStripe\ORM\RelationList;
use SilverStripe\ORM\SS_List;
use SilverStripe\ORM\ValidationException;
Expand Down Expand Up @@ -201,6 +202,12 @@ public function ItemEditForm()
$key = $list->getForeignKey();
$id = $list->getForeignID();
$this->record->$key = $id;
// If the list is polymorphic, add the foreign class as well.
if ($list instanceof PolymorphicHasManyList) {
$classKey = $list->getForeignClassKey();
$class = $list->getForeignClass();
$this->record->$classKey = $class;
}
}

if (!$this->record->canView()) {
Expand Down

0 comments on commit 95ede91

Please sign in to comment.