You are here

protected function DateRecurModularWidgetFieldsTrait::getVisibilityStates in Recurring Date Field Modular Widgets 8

Same name and namespace in other branches
  1. 3.x src/DateRecurModularWidgetFieldsTrait.php \Drupal\date_recur_modular\DateRecurModularWidgetFieldsTrait::getVisibilityStates()
  2. 2.x src/DateRecurModularWidgetFieldsTrait.php \Drupal\date_recur_modular\DateRecurModularWidgetFieldsTrait::getVisibilityStates()

Builds a #states array for an element dependant on mode selected.

Parameters

array $element: The element currently built.

array $modes: An array of modes which allow an element to be visible.

Return value

array An array suitable for assignment to a form API '#states' key.

2 calls to DateRecurModularWidgetFieldsTrait::getVisibilityStates()
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/DateRecurModularWidgetFieldsTrait.php, line 154

Class

DateRecurModularWidgetFieldsTrait
Trait containing convenience methods for generating whole form fields.

Namespace

Drupal\date_recur_modular

Code

protected function getVisibilityStates(array $element, array $modes) : array {
  $modeFieldName = $this
    ->getName($element, [
    'mode',
  ]);
  $conditions = [];
  foreach ($modes as $mode) {
    if (count($conditions) > 0) {
      $conditions[] = 'or';
    }
    $conditions[] = [
      ':input[name="' . $modeFieldName . '"]' => [
        'value' => $mode,
      ],
    ];
  }
  return [
    'visible' => $conditions,
  ];
}