File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,9 +37,28 @@ public function updating(Model $field): void
3737 }
3838
3939 $ field ->setAttribute ('name ' , $ name );
40+ $ this ->preventOptionRemoval ($ field );
4041 $ this ->validateOptions ($ field );
4142 }
4243
44+ private function preventOptionRemoval (Model $ field ): void
45+ {
46+ $ original = array_map (
47+ static fn (array $ option ): string => (string ) ($ option ['key ' ] ?? '' ),
48+ (array ) $ field ->getOriginal ('options ' ),
49+ );
50+ $ current = array_map (
51+ static fn (array $ option ): string => (string ) ($ option ['key ' ] ?? '' ),
52+ (array ) $ field ->getAttribute ('options ' ),
53+ );
54+
55+ foreach ($ original as $ key ) {
56+ if (! in_array ($ key , $ current , true )) {
57+ throw new InvalidArgumentException ("Custom field option [ {$ key }] cannot be removed. " );
58+ }
59+ }
60+ }
61+
4362 private function validateOptions (Model $ field ): void
4463 {
4564 $ seen = [];
You can’t perform that action at this time.
0 commit comments