public static function DateRecurModularSierraWidget::buildRruleFromRecurrenceOption in Recurring Date Field Modular Widgets 8
Same name and namespace in other branches
- 3.x src/Plugin/Field/FieldWidget/DateRecurModularSierraWidget.php \Drupal\date_recur_modular\Plugin\Field\FieldWidget\DateRecurModularSierraWidget::buildRruleFromRecurrenceOption()
- 2.x src/Plugin/Field/FieldWidget/DateRecurModularSierraWidget.php \Drupal\date_recur_modular\Plugin\Field\FieldWidget\DateRecurModularSierraWidget::buildRruleFromRecurrenceOption()
Builds a RRULE string from a preset option given a particular start date.
Parameters
\DateTime $startDate: A start date.
string $recurrenceOption: A recurrence option.
Return value
string A RRULE string.
1 call to DateRecurModularSierraWidget::buildRruleFromRecurrenceOption()
- DateRecurModularSierraWidget::validateModularWidget in src/
Plugin/ Field/ FieldWidget/ DateRecurModularSierraWidget.php - Validates the widget.
File
- src/
Plugin/ Field/ FieldWidget/ DateRecurModularSierraWidget.php, line 857
Class
- DateRecurModularSierraWidget
- Date recur sierra widget.
Namespace
Drupal\date_recur_modular\Plugin\Field\FieldWidgetCode
public static function buildRruleFromRecurrenceOption(\DateTime $startDate, string $recurrenceOption) : string {
$weekdaysKeys = [
'SU',
'MO',
'TU',
'WE',
'TH',
'FR',
'SA',
];
$byDay = $weekdaysKeys[$startDate
->format('w')];
switch ($recurrenceOption) {
case 'daily':
return 'FREQ=DAILY';
case 'weekly_oneday':
return 'FREQ=WEEKLY;BYDAY=' . $byDay;
case 'monthly_th_weekday':
$monthWeekdayNth = static::getMonthWeekdayNth($startDate);
return sprintf('FREQ=MONTHLY;BYDAY=%s;BYSETPOS=%s', $byDay, $monthWeekdayNth);
case 'yearly_monthday':
return sprintf('FREQ=YEARLY;BYMONTH=%s;BYMONTHDAY=%s', $startDate
->format('n'), $startDate
->format('j'));
case 'weekdayly':
return 'FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR';
}
return '';
}