protected function DateRecurModularOscarWidget::getMode in Recurring Date Field Modular Widgets 8
Same name and namespace in other branches
- 3.x src/Plugin/Field/FieldWidget/DateRecurModularOscarWidget.php \Drupal\date_recur_modular\Plugin\Field\FieldWidget\DateRecurModularOscarWidget::getMode()
- 2.x src/Plugin/Field/FieldWidget/DateRecurModularOscarWidget.php \Drupal\date_recur_modular\Plugin\Field\FieldWidget\DateRecurModularOscarWidget::getMode()
Determine the best suitable mode for a date recur field item.
Parameters
\Drupal\date_recur\Plugin\Field\FieldType\DateRecurItem $item: A date recur field item.
Return value
string|null A mode.
Overrides DateRecurModularWidgetBase::getMode
File
- src/
Plugin/ Field/ FieldWidget/ DateRecurModularOscarWidget.php, line 132
Class
- DateRecurModularOscarWidget
- Date recur opening hours widget.
Namespace
Drupal\date_recur_modular\Plugin\Field\FieldWidgetCode
protected function getMode(DateRecurItem $item) : ?string {
try {
$helper = $item
->getHelper();
} catch (DateRecurHelperArgumentException $e) {
return NULL;
}
$rules = $helper
->getRules();
$rule = reset($rules);
if (FALSE === $rule) {
// This widget supports one RRULE per field value.
return NULL;
}
$frequency = $rule
->getFrequency();
$parts = $rule
->getParts();
if ('DAILY' === $frequency) {
/** @var int|null $count */
$count = $parts['COUNT'] ?? NULL;
return $count && $count > 1 ? static::MODE_MULTIDAY : static::MODE_ONCE;
}
elseif ('WEEKLY' === $frequency) {
/** @var int|null $interval */
$interval = $parts['INTERVAL'] ?? NULL;
return [
1 => static::MODE_WEEKLY,
2 => static::MODE_FORTNIGHTLY,
][$interval] ?? NULL;
}
elseif ('MONTHLY' === $frequency) {
return static::MODE_MONTHLY;
}
return NULL;
}