You are here

public function DateRecurDefaultWidget::validateRrule in Recurring Dates Field 8

#element_validate callback to validate the repeat rule.

Parameters

array $element: An associative array containing the properties and children of the generic form element.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

array $complete_form: The complete form structure.

File

src/Plugin/Field/FieldWidget/DateRecurDefaultWidget.php, line 124

Class

DateRecurDefaultWidget
Plugin implementation of the 'date_recur_default_widget' widget.

Namespace

Drupal\date_recur\Plugin\Field\FieldWidget

Code

public function validateRrule(array &$element, FormStateInterface $form_state, array &$complete_form) {
  if (!empty($element['rrule']['#value']) && $element['value']['#value']['object'] instanceof DrupalDateTime) {
    try {
      DateRecurRRule::validateRule($element['rrule']['#value'], $element['value']['#value']['object']);
    } catch (\InvalidArgumentException $e) {
      $form_state
        ->setError($element, $this
        ->t('Invalid repeat rule: %message', [
        '%message' => $e
          ->getMessage(),
      ]));
    }
  }
}