You are here

function Date::build_group_validate in Views (for Drupal 7) 8.3

Validate the build group options form.

Overrides FilterPluginBase::build_group_validate

File

lib/Drupal/views/Plugin/views/filter/Date.php, line 110
Definition of Drupal\views\Plugin\views\filter\Date.

Class

Date
Filter to handle dates stored as a timestamp.

Namespace

Drupal\views\Plugin\views\filter

Code

function build_group_validate($form, &$form_state) {

  // Special case to validate grouped date filters, this is because the
  // $group['value'] array contains the type of filter (date or offset)
  // and therefore the number of items the comparission has to be done
  // against 'one' instead of 'zero'.
  foreach ($form_state['values']['options']['group_info']['group_items'] as $id => $group) {
    if (empty($group['remove'])) {

      // Check if the title is defined but value wasn't defined.
      if (!empty($group['title'])) {
        if (!is_array($group['value']) && empty($group['value']) || is_array($group['value']) && count(array_filter($group['value'])) == 1) {
          form_error($form['group_info']['group_items'][$id]['value'], t('The value is required if title for this item is defined.'));
        }
      }

      // Check if the value is defined but title wasn't defined.
      if (!is_array($group['value']) && !empty($group['value']) || is_array($group['value']) && count(array_filter($group['value'])) > 1) {
        if (empty($group['title'])) {
          form_error($form['group_info']['group_items'][$id]['title'], t('The title is required if value for this item is defined.'));
        }
      }
    }
  }
}