Skip to content

Instantly share code, notes, and snippets.

@shaneonabike
Created September 11, 2018 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaneonabike/bee47684cac5d9a32e23aaccb1ad46e1 to your computer and use it in GitHub Desktop.
Save shaneonabike/bee47684cac5d9a32e23aaccb1ad46e1 to your computer and use it in GitHub Desktop.
Drupal Timefield exposed filter
<?php
/**
* Alter the exposed form for the projects view
*
* $form
* Relative form that is being created
* $form_state
* Existing statee
*/
function yourmodule_form_views_exposed_form_alter(&$form, &$form_state, $form_id) {
// Determine if hour is attached as exposed filter
if (!empty($form['hour'])) {
// Add the JS code to make this happen
$js_settings = array('filter-project-event-time' => array(
'showLeadingZero' => TRUE,
'timeSeparator' => ':',
'showPeriod' => FALSE,
'showPeriodLabels' => FALSE,
'periodSeparator' => '',
'amPmText' => '',
'showMinutesLeadingZero' => TRUE,
'showCloseButton' => TRUE,
'closeButtonText' => t('Done'),
'showNowButton' => FALSE,
'showDeselectButton' => FALSE,
'deselectButtonText' => t('Deselect'),
'myPosition' => 'left top',
'atPosition' => 'left bottom',
)
);
$form['#attached']['library'][] = array('timefield', 'timepicker');
$form['#attached']['js'] = array(
drupal_get_path('module', 'timefield') . '/js/timefield.js',
array(
'data' => array('timefield' => $js_settings),
'type' => 'setting',
)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment