Exemplo n.º 1
0
 /**
  * @todo.
  */
 function views_formats($granularity, $type = 'sql')
 {
     if (empty($granularity)) {
         return DATE_FORMAT_ISO;
     }
     $formats = array('display', 'sql');
     // Start with the site long date format and add seconds to it.
     $long = str_replace(':i', ':i:s', variable_get('date_format_long', 'l, F j, Y - H:i'));
     switch ($granularity) {
         case 'year':
             $formats['display'] = 'Y';
             $formats['sql'] = 'Y';
             break;
         case 'month':
             $formats['display'] = DateGranularity::limitFormat($long, array('year', 'month'));
             $formats['sql'] = 'Y-m';
             break;
         case 'day':
             $formats['display'] = DateGranularity::limitFormat($long, array('year', 'month', 'day'));
             $formats['sql'] = 'Y-m-d';
             break;
         case 'hour':
             $formats['display'] = DateGranularity::limitFormat($long, array('year', 'month', 'day', 'hour'));
             $formats['sql'] = 'Y-m-d\\TH';
             break;
         case 'minute':
             $formats['display'] = DateGranularity::limitFormat($long, array('year', 'month', 'day', 'hour', 'minute'));
             $formats['sql'] = 'Y-m-d\\TH:i';
             break;
         case 'second':
             $formats['display'] = DateGranularity::limitFormat($long, array('year', 'month', 'day', 'hour', 'minute', 'second'));
             $formats['sql'] = 'Y-m-d\\TH:i:s';
             break;
         case 'week':
             $formats['display'] = 'F j Y (W)';
             $formats['sql'] = 'Y-\\WW';
             break;
     }
     return $formats[$type];
 }
Exemplo n.º 2
0
/**
 * Alter the date_combo element after the Date module is finished with it.
 *
 * @param array $element
 *   The $element array.
 * @param array $form_state
 *   A keyed array containing the current state of the form.
 * @param array $context
 *   An associative array containing the following keys:
 *   - field: The $field array.
 *   - instance: The $instance array.
 *   - form: Nested array of form elements that comprise the form.
 */
function hook_date_combo_process_alter(&$element, &$form_state, $context)
{
    $field = $context['field'];
    $instance = $context['instance'];
    $field_name = $element['#field_name'];
    $delta = $element['#delta'];
    // Add a date repeat form element, if needed.
    // We delayed until this point so we don't bother adding it to hidden fields.
    if (date_is_repeat_field($field, $instance)) {
        $item = $element['#value'];
        $element['rrule'] = array('#type' => 'date_repeat_rrule', '#theme_wrappers' => array('date_repeat_rrule'), '#default_value' => isset($item['rrule']) ? $item['rrule'] : '', '#date_timezone' => $element['#date_timezone'], '#date_format' => DateGranularity::limitFormat(date_input_format($element, $field, $instance), $field['settings']['granularity']), '#date_text_parts' => (array) $instance['widget']['settings']['text_parts'], '#date_increment' => $instance['widget']['settings']['increment'], '#date_year_range' => $instance['widget']['settings']['year_range'], '#date_label_position' => $instance['widget']['settings']['label_position'], '#date_repeat_widget' => str_replace('_repeat', '', $instance['widget']['type']), '#date_flexible' => 0, '#weight' => $instance['widget']['weight'] + 0.4);
    }
}