Skip to content

Commit ba63492

Browse files
committed
Always populate all available fields of Weekly/MonthlyFields
Don't only populate fields that have been choosen by the user, but also that wern't selected with the unchecked value, just as a normal form frequest does.
1 parent 3a4264c commit ba63492

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

src/FormElement/ScheduleElement/Common/FieldsUtils.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ public function loadRRule(RRule $rule): array
8585
$values = [];
8686
$isMonthly = $rule->getFrequency() === RRule::MONTHLY;
8787
if ($isMonthly && (! empty($rule->getByMonthDay()) || empty($rule->getByDay()))) {
88-
foreach ($rule->getByMonthDay() ?? [] as $value) {
89-
$values["day$value"] = 'y';
88+
$monthDays = $rule->getByMonthDay() ?? [];
89+
foreach (range(1, $this->availableFields) as $value) {
90+
$values["day$value"] = in_array((string) $value, $monthDays, true) ? 'y' : 'n';
9091
}
9192

9293
$values['runsOn'] = MonthlyFields::RUNS_EACH;

src/FormElement/ScheduleElement/WeeklyFields.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,15 @@ public function getSelectedWeekDays(): array
7878
/**
7979
* Transform the given weekdays into key=>value array that can be populated
8080
*
81-
* @param array $days
81+
* @param array $weekdays
8282
*
8383
* @return array
8484
*/
85-
public function loadWeekDays(array $days): array
85+
public function loadWeekDays(array $weekdays): array
8686
{
8787
$values = [];
88-
foreach ($days as $day) {
89-
$weekDays = strtoupper($day);
90-
if (! isset($this->weekdays[$weekDays])) {
91-
throw new InvalidArgumentException(sprintf('Invalid weekday provided: %s', $day));
92-
}
93-
94-
$values[$weekDays] = 'y';
88+
foreach ($this->weekdays as $weekday => $_) {
89+
$values[$weekday] = in_array($weekday, $weekdays, true) ? 'y' : 'n';
9590
}
9691

9792
return $values;

0 commit comments

Comments
 (0)