Skip to content

Commit

Permalink
Improve support for BackedEnums
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeTowers authored Sep 3, 2023
1 parent ca85e3c commit 32f25ef
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions modules/backend/classes/FormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -700,25 +700,26 @@ protected function getFieldNameFromData($fieldName, $data, $default = null)
if ($result instanceof Model && $result->hasRelation($key)) {
if ($key == $lastField) {
$result = $result->getRelationValue($key) ?: $default;
}
else {
} else {
$result = $result->{$key};
}
}
elseif (is_array($result)) {
} elseif (is_array($result)) {
if (!array_key_exists($key, $result)) {
return $default;
}
$result = $result[$key];
}
else {
} else {
if (!isset($result->{$key})) {
return $default;
}
$result = $result->{$key};
}
}

if ($result instanceof BackedEnum) {
$result = $result->value;
}

return $result;
}
}

0 comments on commit 32f25ef

Please sign in to comment.