Skip to main content
improved formatting
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

Found a work around,

keeping in mind pager works for calendar view by changing date in url. So down below goes the work around,please let me know the better way to do that.Till then

Workaround

created a custom form with fields as day,month,year field type as select(dropdown).

Code snippet for the form with submit handler

I found a work around, keeping in mind that the pager works for calendar view by changing date in the URL.

I created a custom form with fields as day, month, year whose field type is select (dropdown).

This is the code for the form and the submission handler.

Now call this form in your calendar view in view header print drupal_render(drupal_get_form(mymodule_get_event_view_date_filter));

Now call this form in your calendar view in view header print.

drupal_render(drupal_get_form(mymodule_get_event_view_date_filter));

Found a work around,

keeping in mind pager works for calendar view by changing date in url. So down below goes the work around,please let me know the better way to do that.Till then

Workaround

created a custom form with fields as day,month,year field type as select(dropdown).

Code snippet for the form with submit handler

Now call this form in your calendar view in view header print drupal_render(drupal_get_form(mymodule_get_event_view_date_filter));

I found a work around, keeping in mind that the pager works for calendar view by changing date in the URL.

I created a custom form with fields as day, month, year whose field type is select (dropdown).

This is the code for the form and the submission handler.

Now call this form in your calendar view in view header print.

drupal_render(drupal_get_form(mymodule_get_event_view_date_filter));
Source Link
arpitr
  • 7.9k
  • 2
  • 23
  • 48

Found a work around,

keeping in mind pager works for calendar view by changing date in url. So down below goes the work around,please let me know the better way to do that.Till then

Workaround

created a custom form with fields as day,month,year field type as select(dropdown).

Code snippet for the form with submit handler

function mymodule_get_event_view_date_filter($form, &$form_state) {
  $form = array();
  $year = date('Y');
  $year_options = array(
    $year - 4 => t($year - 4),
    $year - 3 => t($year - 3),
    $year - 2 => t($year - 2),
    $year - 1 => t($year - 1),
    $year => t($year),
    $year + 1 => t($year + 1),
    $year + 2 => t($year + 2),
    $year + 3 => t($year + 3),
    $year + 4 => t($year + 4),
  );
  $month = date('m');
  $month_options = array(
    '1' => 'Jan',
    '2' => 'Feb',
    '3' => 'March',
    '4' => 'April',
    '5' => 'May',
    '6' => 'June',
    '7' => 'July',
    '8' => 'Aug',
    '9' => 'Sep',
    '10' => 'Oct',
    '11' => 'Nov',
    '12' => 'Dec',
  );
  $form['event-date-container'] = array(
    '#type' => 'container',
    '#prefix' => '<div id="event-date-container">',
    '#suffix' => '</div>',
  );
  $form['event-date-container']['year'] = array(
    '#type' => 'select',
    '#options' => $year_options,
    '#prefix' => '<div id="event-year">',
    '#default_value' => isset($_SESSION['event']['year']) ? $_SESSION['event']['year'] : $year,
    '#suffix' => '</div>',
  );
  $form['event-date-container']['month'] = array(
    '#type' => 'select',
    '#options' => $month_options,
    '#prefix' => '<div id="event-month">',
    '#default_value' => isset($_SESSION['event']['month']) ? $_SESSION['event']['month'] : $month,
    '#suffix' => '</div>',
  );
  $form['event-date-container']['submit_form'] = array(
    '#type' => 'submit',
    '#value' => t('Apply'),
    '#submit' => array('_mymodule_event_view_date_submit'),
  );
  unset($_SESSION['event']);
  return $form;
}

function _mymodule_event_view_date_submit($form, $form_state) {
  global $base_url;
  $_SESSION['event']['year'] = $form_state['values']['year'];
  $_SESSION['event']['month'] = $form_state['values']['month'];
  drupal_goto('calendar-node-field-event-date/month/' . $form_state['values']['year'] . '-' . $form_state['values']['month']);
}

Now call this form in your calendar view in view header print drupal_render(drupal_get_form(mymodule_get_event_view_date_filter));