Skip to content

Commit

Permalink
Don't call newClassInstance on link that haven't been saved yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Rainville committed Oct 28, 2020
1 parent be42b5b commit 6777e41
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Models/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SilverStripe\Link\Models;

use InvalidArgumentException;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\FieldList;
use SilverStripe\Link\JsonData;
use SilverStripe\Link\Type\Registry;
Expand Down Expand Up @@ -84,7 +85,12 @@ function setData($data): JsonData

$jsonData = $this;
if ($this->ClassName !== get_class($type)) {
$jsonData = $this->newClassInstance(get_class($type));
if ($this->isInDB()) {
$jsonData = $this->newClassInstance(get_class($type));
} else {
$jsonData = Injector::inst()->create(get_class($type));
}

}

foreach ($data as $key => $value) {
Expand Down

0 comments on commit 6777e41

Please sign in to comment.