You are here

protected function DateRecurModularAlphaWidget::getFieldModes in Recurring Date Field Modular Widgets 3.x

Same name and namespace in other branches
  1. 8 src/Plugin/Field/FieldWidget/DateRecurModularAlphaWidget.php \Drupal\date_recur_modular\Plugin\Field\FieldWidget\DateRecurModularAlphaWidget::getFieldModes()
  2. 2.x src/Plugin/Field/FieldWidget/DateRecurModularAlphaWidget.php \Drupal\date_recur_modular\Plugin\Field\FieldWidget\DateRecurModularAlphaWidget::getFieldModes()

Get field modes for generating #states arrays.

Determines whether some fields should be visible.

Parameters

\Drupal\date_recur\DateRecurPartGrid $grid: A part grid object.

Return value

array Field modes.

1 call to DateRecurModularAlphaWidget::getFieldModes()
DateRecurModularAlphaWidget::formElement in src/Plugin/Field/FieldWidget/DateRecurModularAlphaWidget.php
Returns the form for a single field widget.

File

src/Plugin/Field/FieldWidget/DateRecurModularAlphaWidget.php, line 509

Class

DateRecurModularAlphaWidget
Date recur alpha widget.

Namespace

Drupal\date_recur_modular\Plugin\Field\FieldWidget

Code

protected function getFieldModes(DateRecurPartGrid $grid) : array {
  $fieldModes = [];
  if ($grid
    ->isPartAllowed('DAILY', 'COUNT')) {
    $fieldModes['daily_count'][] = static::MODE_MULTIDAY;
  }
  if ($grid
    ->isPartAllowed('WEEKLY', 'BYDAY')) {
    $fieldModes['weekdays'][] = static::MODE_WEEKLY;
    $fieldModes['weekdays'][] = static::MODE_FORTNIGHTLY;
  }
  $count = $grid
    ->isPartAllowed('WEEKLY', 'COUNT');
  $until = $grid
    ->isPartAllowed('WEEKLY', 'UNTIL');
  if ($count || $until) {
    $fieldModes['ends_mode'][] = static::MODE_WEEKLY;
    $fieldModes['ends_mode'][] = static::MODE_FORTNIGHTLY;
    if ($count) {
      $fieldModes['ends_count'][] = static::MODE_WEEKLY;
      $fieldModes['ends_count'][] = static::MODE_FORTNIGHTLY;
    }
    if ($until) {
      $fieldModes['ends_date'][] = static::MODE_WEEKLY;
      $fieldModes['ends_date'][] = static::MODE_FORTNIGHTLY;
    }
  }
  if ($grid
    ->isPartAllowed('MONTHLY', 'BYSETPOS')) {
    $fieldModes['ordinals'][] = static::MODE_MONTHLY;
  }
  if ($grid
    ->isPartAllowed('MONTHLY', 'BYDAY')) {
    $fieldModes['weekdays'][] = static::MODE_MONTHLY;
  }
  $count = $grid
    ->isPartAllowed('MONTHLY', 'COUNT');
  $until = $grid
    ->isPartAllowed('MONTHLY', 'UNTIL');
  if ($count || $until) {
    $fieldModes['ends_mode'][] = static::MODE_MONTHLY;
    if ($count) {
      $fieldModes['ends_count'][] = static::MODE_MONTHLY;
    }
    if ($until) {
      $fieldModes['ends_date'][] = static::MODE_MONTHLY;
    }
  }
  return $fieldModes;
}