@@ -829,9 +829,9 @@ protected function assembleMultiDayOptions(FieldsetElement $options): DateTime
829
829
]);
830
830
$ from = $ options ->getElement ('from_day ' );
831
831
832
- $ selectedDay = (int ) $ from ->getValue ();
832
+ $ selectedFromDay = (int ) $ from ->getValue ();
833
833
834
- for ($ i = 1 ; $ i <= $ selectedDay ; $ i ++) {
834
+ for ($ i = 1 ; $ i <= $ selectedFromDay ; $ i ++) {
835
835
$ toDays [$ i ] = sprintf ('%s (%s) ' , $ toDays [$ i ], $ this ->translate ('Next week ' ));
836
836
}
837
837
@@ -840,22 +840,7 @@ protected function assembleMultiDayOptions(FieldsetElement $options): DateTime
840
840
'required ' => true ,
841
841
'options ' => $ toDays ,
842
842
'value ' => 7 ,
843
- 'label ' => $ this ->translate ('To ' , 'notifications.rotation ' ),
844
- 'validators ' => [
845
- new CallbackValidator (function ($ value , $ validator ) use ($ options ) {
846
- if ($ value !== $ options ->getValue ('from_day ' )) {
847
- return true ;
848
- }
849
-
850
- if ($ options ->getValue ('from_at ' ) < $ options ->getValue ('to_at ' )) {
851
- $ validator ->addMessage ($ this ->translate ('Shifts cannot last longer than 7 days ' ));
852
-
853
- return false ;
854
- }
855
-
856
- return true ;
857
- })
858
- ]
843
+ 'label ' => $ this ->translate ('To ' , 'notifications.rotation ' )
859
844
]);
860
845
$ to = $ options ->getElement ('to_day ' );
861
846
@@ -867,17 +852,24 @@ protected function assembleMultiDayOptions(FieldsetElement $options): DateTime
867
852
'label ' => $ this ->translate ('Handoff every ' )
868
853
]);
869
854
855
+ $ timeOptions = $ this ->getTimeOptions ();
870
856
$ fromAt = $ options ->createElement ('select ' , 'from_at ' , [
871
857
'class ' => 'autosubmit ' ,
872
858
'required ' => true ,
873
- 'options ' => $ this -> getTimeOptions ()
859
+ 'options ' => $ timeOptions
874
860
]);
875
861
$ options ->registerElement ($ fromAt );
876
862
863
+ if ($ selectedFromDay === (int ) $ to ->getValue ()) {
864
+ $ selectedFromAt = $ fromAt ->getValue ();
865
+ $ keyIndex = array_search ($ selectedFromAt , array_keys ($ timeOptions ));
866
+ $ timeOptions = array_slice ($ timeOptions , 0 , $ keyIndex + 1 , true );
867
+ }
868
+
877
869
$ toAt = $ options ->createElement ('select ' , 'to_at ' , [
878
870
'class ' => 'autosubmit ' ,
879
871
'required ' => true ,
880
- 'options ' => $ this -> getTimeOptions ()
872
+ 'options ' => $ timeOptions
881
873
]);
882
874
$ options ->registerElement ($ toAt );
883
875
0 commit comments