1 views_handler_filter.inc views_handler_filter::build_group_validate($form, &$form_state)

Validate the build group options form.

File

core/modules/views/handlers/views_handler_filter.inc, line 604
@todo.

Class

views_handler_filter
Base class for filters.

Code

function build_group_validate($form, &$form_state) {
  if (!empty($form_state['values']['options']['group_info'])) {
    if (empty($form_state['values']['options']['group_info']['identifier'])) {
      form_error($form['group_info']['identifier'], t('The identifier is required if the filter is exposed.'));
    }

    if (!empty($form_state['values']['options']['group_info']['identifier']) && $form_state['values']['options']['group_info']['identifier'] == 'value') {
      form_error($form['group_info']['identifier'], t('This identifier is not allowed.'));
    }

    if (!$this->view->display_handler->is_identifier_unique($form_state['id'], $form_state['values']['options']['group_info']['identifier'])) {
      form_error($form['group_info']['identifier'], t('This identifier is used by another handler.'));
    }
  }

  if (!empty($form_state['values']['options']['group_info']['group_items'])) {
    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']) && trim($group['value']) == "") || 
            (is_array($group['value']) && count(array_filter($group['value'], '_views_array_filter_zero')) == 0)) {
            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']) && trim($group['value']) != "") || 
          (is_array($group['value']) && count(array_filter($group['value'], '_views_array_filter_zero')) > 0)) {
          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.'));
          }
        }
      }
    }
  }
}