@@ -895,18 +895,14 @@ protected function assembleMultiDayOptions(FieldsetElement $options): DateTime
895
895
$ toDays [$ i ] = sprintf ('%s (%s) ' , $ day , $ this ->translate ('Next week ' ));
896
896
}
897
897
898
- $ options ->addElement ('hidden ' , 'to_day ' );
899
- $ options ->addElement ('hidden ' , 'to_at ' );
900
-
901
- $ options ->addElement ('select ' , 'to_day_ignored ' , [
898
+ $ options ->addElement ('select ' , 'to_day ' , [
902
899
'class ' => 'autosubmit ' ,
903
900
'required ' => true ,
904
- 'ignore ' => true ,
905
901
'options ' => $ toDays ,
906
- 'value ' => $ options -> getValue ( ' to_day ' , 7 ) ,
902
+ 'value ' => 7 ,
907
903
'label ' => $ this ->translate ('To ' , 'notifications.rotation ' )
908
904
]);
909
- $ to = $ options ->getElement ('to_day_ignored ' );
905
+ $ to = $ options ->getElement ('to_day ' );
910
906
911
907
$ options ->addElement ('number ' , 'interval ' , [
912
908
'required ' => true ,
@@ -923,14 +919,22 @@ protected function assembleMultiDayOptions(FieldsetElement $options): DateTime
923
919
'options ' => $ timeOptions
924
920
]);
925
921
$ options ->registerElement ($ fromAt );
922
+ $ selectedFromAt = $ fromAt ->getValue ();
923
+
924
+ $ removeOutOfRangeToAtOptions = function () use ($ selectedFromAt , $ timeOptions ) {
925
+ return array_slice (
926
+ $ timeOptions ,
927
+ 0 ,
928
+ array_search ($ selectedFromAt , array_keys ($ timeOptions ), true ) + 1 ,
929
+ true
930
+ );
931
+ };
926
932
927
933
$ timeOptionsFirstKey = array_key_first ($ timeOptions );
928
934
$ selectedToDay = (int ) $ to ->getValue ();
929
935
$ endOfDay = 'endOfDay ' ;
930
936
if ($ selectedFromDay === $ selectedToDay ) {
931
- $ selectedFromAt = $ fromAt ->getValue ();
932
- $ keyIndex = array_search ($ selectedFromAt , array_keys ($ timeOptions ));
933
- $ timeOptions = array_slice ($ timeOptions , 0 , $ keyIndex + 1 , true );
937
+ $ timeOptions = $ removeOutOfRangeToAtOptions ();
934
938
} else {
935
939
$ timeOptions [$ endOfDay ] = sprintf (
936
940
'%s (%s) ' ,
@@ -939,24 +943,23 @@ protected function assembleMultiDayOptions(FieldsetElement $options): DateTime
939
943
);
940
944
}
941
945
942
- $ toAt = $ options ->createElement ('select ' , 'to_at_ignored ' , [
946
+ $ toAt = $ options ->createElement ('select ' , 'to_at ' , [
943
947
'class ' => 'autosubmit ' ,
944
948
'required ' => true ,
945
- 'ignore ' => true ,
946
- 'options ' => $ timeOptions ,
947
- 'value ' => $ options ->getValue ('to_at ' ),
949
+ 'options ' => $ timeOptions
948
950
]);
949
951
$ options ->registerElement ($ toAt );
950
952
951
- $ selectedToAt = $ toAt ->getValue ();
952
-
953
- if ($ selectedToAt === $ endOfDay ) {
953
+ if ($ toAt ->getValue () === $ endOfDay ) {
954
954
$ selectedToDay = $ selectedToDay === 7 ? 1 : $ selectedToDay + 1 ;
955
- $ selectedToAt = $ timeOptionsFirstKey ;
956
- }
957
955
958
- $ options ->getElement ('to_day ' )->setValue ($ selectedToDay );
959
- $ options ->getElement ('to_at ' )->setValue ($ selectedToAt );
956
+ if ($ selectedFromDay === $ selectedToDay ) {
957
+ $ toAt ->setOptions ($ removeOutOfRangeToAtOptions ());
958
+ }
959
+
960
+ $ to ->setValue ($ selectedToDay );
961
+ $ toAt ->setValue ($ timeOptionsFirstKey );
962
+ }
960
963
961
964
$ from ->prependWrapper (
962
965
(new HtmlDocument ())->addHtml (
0 commit comments