function interval_field_widget_form in Interval Field 7
Implements hook_field_widget_form().
File
- ./
interval.module, line 210 - Defines an interval field @copyright Copyright(c) 2011 Rowlands Group @license GPL v2+ http://www.fsf.org/licensing/licenses/gpl.html @author Lee Rowlands leerowlands at rowlandsgroup dot com
Code
function interval_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
// Convenience variables.
$value = isset($items[$delta]) ? $items[$delta] : array(
'interval' => NULL,
'period' => NULL,
);
$field_name = $instance['field_name'];
// We need to check our form_state values for ajax completion.
if (isset($form_state['values']) && !empty($form_state['values'][$field_name][$langcode][$delta])) {
// We use the current form state values instead of those from the db.
$value = $form_state['values'][$field_name][$langcode][$delta];
}
$element['#default_value'] = $value;
$settings = $instance['settings'];
$widget = $instance['widget'];
// Available periods.
if (isset($settings['allowed_periods'])) {
$element['#periods'] = array_keys(array_filter($settings['allowed_periods']));
}
switch ($widget['type']) {
case 'interval_default':
$element += array(
'#type' => 'interval',
);
break;
}
return $element;
}