From 4fa00f1c7b9bdd89a838f66a45e857762faecaf6 Mon Sep 17 00:00:00 2001 From: Sam Georges Date: Mon, 28 Jul 2014 17:28:39 +1000 Subject: [PATCH] Fixes an issue where unfilled relations are not populated in forms --- modules/backend/widgets/Form.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/backend/widgets/Form.php b/modules/backend/widgets/Form.php index 44aaec537..987e958d5 100644 --- a/modules/backend/widgets/Form.php +++ b/modules/backend/widgets/Form.php @@ -600,14 +600,16 @@ class Form extends WidgetBase /* * Loop the field key parts and build a value. - * To support relations only the last ield should return the + * To support relations only the last field should return the * relation value, all others will look up the relation object as normal. */ foreach ($keyParts as $key) { - if ($key == $lastField && $result instanceof Model && $result->hasRelation($key)) { - if (!$result = $result->getRelationValue($key)) - return $defaultValue; + if ($result instanceof Model && $result->hasRelation($key)) { + if ($key == $lastField) + $result = $result->getRelationValue($key) ?: $defaultValue; + else + $result = $result->{$key}; } elseif (is_array($result)) { if (!array_key_exists($key, $result)) return $defaultValue;