protected function DateRecurModularUtilityTrait::getRule in Recurring Date Field Modular Widgets 2.x
Same name and namespace in other branches
- 8 src/DateRecurModularUtilityTrait.php \Drupal\date_recur_modular\DateRecurModularUtilityTrait::getRule()
- 3.x src/DateRecurModularUtilityTrait.php \Drupal\date_recur_modular\DateRecurModularUtilityTrait::getRule()
Attempts to get the first valid rule from a date recur field item.
Parameters
\Drupal\date_recur\Plugin\Field\FieldType\DateRecurItem $item: A date recur field item.
Return value
\Drupal\date_recur\DateRecurRuleInterface|null A rule.
2 calls to DateRecurModularUtilityTrait::getRule()
- DateRecurModularAlphaWidget::formElement in src/
Plugin/ Field/ FieldWidget/ DateRecurModularAlphaWidget.php - Returns the form for a single field widget.
- DateRecurModularOscarWidget::formElement in src/
Plugin/ Field/ FieldWidget/ DateRecurModularOscarWidget.php - Returns the form for a single field widget.
File
- src/
DateRecurModularUtilityTrait.php, line 135
Class
- DateRecurModularUtilityTrait
- Trait containing convenience methods for dealing with date recur widgets.
Namespace
Drupal\date_recur_modularCode
protected function getRule(DateRecurItem $item) : ?DateRecurRuleInterface {
try {
$helper = $item
->getHelper();
} catch (DateRecurHelperArgumentException $e) {
return NULL;
}
$rules = $helper
->getRules();
$rule = reset($rules);
return FALSE !== $rule ? $rule : NULL;
}