You are here

protected function DateRecurModularUtilityTrait::getRule in Recurring Date Field Modular Widgets 8

Same name and namespace in other branches
  1. 3.x src/DateRecurModularUtilityTrait.php \Drupal\date_recur_modular\DateRecurModularUtilityTrait::getRule()
  2. 2.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_modular

Code

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;
}