Skip to content

Commit 85f69ca

Browse files
committed
Instead of using the validate_extra method for this, create a method named get_timezone_choices that
simply returns system_get_timezone_list(). Then use 'get_timezone_choices' as the choices_callable parameter for the timezone field. This will automatically perform the choices validation and ensures the package knows this field uses an enum for schema generation purposes. Thanks to @jaredhendrickson13
1 parent d24e8d8 commit 85f69ca

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/SystemTimezone.inc

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class SystemTimezone extends Model {
2424
allow_empty: false,
2525
allow_null: false,
2626
many: false,
27+
choices_callable: 'get_timezone_choices',
2728
help_text: 'Set geographic region name (Continent/Location) to determine the timezone for the firewall.'
2829
);
2930

@@ -40,16 +41,7 @@ class SystemTimezone extends Model {
4041
/*
4142
*
4243
*/
43-
public function validate_extra(): void {
44-
$tzlist = system_get_timezone_list();
45-
46-
$tz = $this->timezone->value;
47-
48-
if ( ! in_array($tz, $tzlist) ) {
49-
throw new ValidationError(
50-
message: "Unknown timezone={$tz}",
51-
response_id: 'TIMEZONE_UNKNOWN_TIMEZONE',
52-
);
53-
}
44+
public function get_timezone_choices(): array {
45+
return system_get_timezone_list();
5446
}
5547
}

0 commit comments

Comments
 (0)