protected function DateRecurModularSierraWidget::getRecurrenceOptions 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::getRecurrenceOptions()
- 2.x src/Plugin/Field/FieldWidget/DateRecurModularSierraWidget.php \Drupal\date_recur_modular\Plugin\Field\FieldWidget\DateRecurModularSierraWidget::getRecurrenceOptions()
Get recurrence options for a select element based on a start date.
Parameters
\DateTime $startDate: A date to base recurrence options.
Return value
array An array of option suitable for select element.
1 call to DateRecurModularSierraWidget::getRecurrenceOptions()
- DateRecurModularSierraWidget::formElement in src/
Plugin/ Field/ FieldWidget/ DateRecurModularSierraWidget.php - Returns the form for a single field widget.
File
- src/
Plugin/ Field/ FieldWidget/ DateRecurModularSierraWidget.php, line 822
Class
- DateRecurModularSierraWidget
- Date recur sierra widget.
Namespace
Drupal\date_recur_modular\Plugin\Field\FieldWidgetCode
protected function getRecurrenceOptions(\DateTime $startDate) : array {
$dayOfMonth = $startDate
->format('j');
$tArgs = [
'@weekday' => $startDate
->format('l'),
'@dayofmonth' => $dayOfMonth,
'@month' => $startDate
->format('F'),
];
$monthWeekdayNth = static::getMonthWeekdayNth($startDate);
$tArgs['@monthweekdaynth'] = $monthWeekdayNth;
$tArgs['@monthweekdayordinal'] = $monthWeekdayNth == 1 ? 'st' : ($monthWeekdayNth == 2 ? 'nd' : ($monthWeekdayNth == 3 ? 'rd' : 'th'));
$options = [];
$options['daily'] = $this
->t('Daily');
$options['weekly_oneday'] = $this
->t('Weekly on @weekday', $tArgs);
$options['monthly_th_weekday'] = $this
->t('Monthly on the @monthweekdaynth@monthweekdayordinal @weekday', $tArgs);
$options['yearly_monthday'] = $this
->t('Annually on @month @dayofmonth', $tArgs);
$options['weekdayly'] = $this
->t('Every weekday (Monday to Friday)');
return $options;
}