Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
2 replaced http://drupal.stackexchange.com/ with https://drupal.stackexchange.com/
source | link

I am trying desperately to get the following working:

Goal: I have a views that displays a list of events. To this views is a date exposed filter attached, with granularity Y-m(year month). I want this filter to filter with Y granularity if only the year is selected, and by Y-m if both are selected. In addition to that, the view is set so that: when no date filter is selected, then filter by upcoming events, else, use the exposed filter value

Issue:

The month is required, even if I alter the form I am suprised by the fact that exposed_form_alter as well as the validation fct are called multiple times, before the view is pre-build and before it is pre-executed, but this might be normal behavior. See here: http://cl.ly/image/1C0t3Z3O0D3W (hook_views_*** dpms the function's name)

Draft:

The solution was inspired by this threadthis thread

function lezoo_form_views_exposed_form_alter(&$form, &$form_state) {
  if($form['#id'] == 'views-exposed-form-teaser-list-panel-pane-1')
  {
   $form['#validate'][] = 'lezoo_views_exposed_form_validate';

  }
}

function lezoo_views_exposed_form_validate(&$form, &$form_state) {

  $handlers = &$form_state['input'];
  foreach ($handlers as $key => $handler) {
    if (
      isset($form[$key]['value']['#type'])
      && $form[$key]['value']['#type'] == 'date_select'
      && $form[$key]['value']['#date_format'] == 'Y-m'
      && $form_state['input'][$key]['value']['month'] == '') {
      $form[$key]['value']['#date_format'] == 'Y';
    unset($form[$key]['value']['#granularity'][2]);
    unset($form_state['input'][$key]['value']['month']);
  }
}
dpm('form validation');
   // dpm($form);
   // dpm('form_state');
   // dpm($form_state);
}


function lezoo_views_query_alter(&$view, &$query) {
  //If a date was selected in the exposed filter, ignore the default date filter '> today'
  $conditions = $view->query->where['1']['conditions'];
  $date_index = 3;
  if(isset($view->query->where['1']['conditions'][$date_index]) &&
    //if a date exposed filter was set
   $view->query->where['1']['conditions'][$date_index]['field'] != 'node.nid')
  {
    unset($view->query->where['1']['conditions'][2]);
  }
} 

I am really stuck here, IRC is not helping unfortunately, and i would really appreciate more insights on this!

Thanks in advance!

I am trying desperately to get the following working:

Goal: I have a views that displays a list of events. To this views is a date exposed filter attached, with granularity Y-m(year month). I want this filter to filter with Y granularity if only the year is selected, and by Y-m if both are selected. In addition to that, the view is set so that: when no date filter is selected, then filter by upcoming events, else, use the exposed filter value

Issue:

The month is required, even if I alter the form I am suprised by the fact that exposed_form_alter as well as the validation fct are called multiple times, before the view is pre-build and before it is pre-executed, but this might be normal behavior. See here: http://cl.ly/image/1C0t3Z3O0D3W (hook_views_*** dpms the function's name)

Draft:

The solution was inspired by this thread

function lezoo_form_views_exposed_form_alter(&$form, &$form_state) {
  if($form['#id'] == 'views-exposed-form-teaser-list-panel-pane-1')
  {
   $form['#validate'][] = 'lezoo_views_exposed_form_validate';

  }
}

function lezoo_views_exposed_form_validate(&$form, &$form_state) {

  $handlers = &$form_state['input'];
  foreach ($handlers as $key => $handler) {
    if (
      isset($form[$key]['value']['#type'])
      && $form[$key]['value']['#type'] == 'date_select'
      && $form[$key]['value']['#date_format'] == 'Y-m'
      && $form_state['input'][$key]['value']['month'] == '') {
      $form[$key]['value']['#date_format'] == 'Y';
    unset($form[$key]['value']['#granularity'][2]);
    unset($form_state['input'][$key]['value']['month']);
  }
}
dpm('form validation');
   // dpm($form);
   // dpm('form_state');
   // dpm($form_state);
}


function lezoo_views_query_alter(&$view, &$query) {
  //If a date was selected in the exposed filter, ignore the default date filter '> today'
  $conditions = $view->query->where['1']['conditions'];
  $date_index = 3;
  if(isset($view->query->where['1']['conditions'][$date_index]) &&
    //if a date exposed filter was set
   $view->query->where['1']['conditions'][$date_index]['field'] != 'node.nid')
  {
    unset($view->query->where['1']['conditions'][2]);
  }
} 

I am really stuck here, IRC is not helping unfortunately, and i would really appreciate more insights on this!

Thanks in advance!

I am trying desperately to get the following working:

Goal: I have a views that displays a list of events. To this views is a date exposed filter attached, with granularity Y-m(year month). I want this filter to filter with Y granularity if only the year is selected, and by Y-m if both are selected. In addition to that, the view is set so that: when no date filter is selected, then filter by upcoming events, else, use the exposed filter value

Issue:

The month is required, even if I alter the form I am suprised by the fact that exposed_form_alter as well as the validation fct are called multiple times, before the view is pre-build and before it is pre-executed, but this might be normal behavior. See here: http://cl.ly/image/1C0t3Z3O0D3W (hook_views_*** dpms the function's name)

Draft:

The solution was inspired by this thread

function lezoo_form_views_exposed_form_alter(&$form, &$form_state) {
  if($form['#id'] == 'views-exposed-form-teaser-list-panel-pane-1')
  {
   $form['#validate'][] = 'lezoo_views_exposed_form_validate';

  }
}

function lezoo_views_exposed_form_validate(&$form, &$form_state) {

  $handlers = &$form_state['input'];
  foreach ($handlers as $key => $handler) {
    if (
      isset($form[$key]['value']['#type'])
      && $form[$key]['value']['#type'] == 'date_select'
      && $form[$key]['value']['#date_format'] == 'Y-m'
      && $form_state['input'][$key]['value']['month'] == '') {
      $form[$key]['value']['#date_format'] == 'Y';
    unset($form[$key]['value']['#granularity'][2]);
    unset($form_state['input'][$key]['value']['month']);
  }
}
dpm('form validation');
   // dpm($form);
   // dpm('form_state');
   // dpm($form_state);
}


function lezoo_views_query_alter(&$view, &$query) {
  //If a date was selected in the exposed filter, ignore the default date filter '> today'
  $conditions = $view->query->where['1']['conditions'];
  $date_index = 3;
  if(isset($view->query->where['1']['conditions'][$date_index]) &&
    //if a date exposed filter was set
   $view->query->where['1']['conditions'][$date_index]['field'] != 'node.nid')
  {
    unset($view->query->where['1']['conditions'][2]);
  }
} 

I am really stuck here, IRC is not helping unfortunately, and i would really appreciate more insights on this!

Thanks in advance!

    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user