function settingsForm(array $form, array &$form_state)
 {
     $element = parent::settingsForm($form, $form_state);
     $element['date_format'] = array('#type' => 'select', '#title' => t('Date entry format'), '#default_value' => $this->getSetting('date_format'), '#options' => $this->formatOptions(), '#description' => t('Control the order and format of the options users see.'), '#weight' => 3, '#fieldset' => 'date_format');
     $form['all_day_toggle'] = array('#type' => 'select', '#title' => t('All day toggle'), '#description' => t("Add an 'All day' checkbox to the form to allow the user to hide or show the time."), '#default_value' => $this->getSetting('all_day_toggle'), '#options' => array(0 => t('No'), 1 => t('Yes')), '#weight' => 2);
     $element['advanced'] = array('#type' => 'fieldset', '#title' => t('Advanced settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#fieldset' => 'date_format', '#weight' => 9);
     $element['advanced']['text_parts'][$key] = array('#type' => 'value', '#value' => (int) in_array($key, (array) $this->getSetting('text_parts')));
     $element['advanced']['text_parts'] = array('#theme' => 'date_text_parts');
     $text_parts = (array) $this->getSetting('text_parts');
     foreach (DateGranularity::granularityNames() as $key => $value) {
         $element['advanced']['text_parts'][$key] = array('#type' => 'radios', '#default_value' => in_array($key, $text_parts) ? 1 : 0, '#options' => array(0 => '', 1 => ''));
     }
     return $element;
 }
 /**
  * @todo.
  */
 public function testTimezone()
 {
     // Create a date fields with combinations of various timezone handling and
     // granularity.
     foreach (array('date') as $field_type) {
         foreach (array('site', 'none', 'date', 'user', 'utc') as $tz_handling) {
             foreach (array('year', 'month', 'day', 'hour', 'minute', 'second') as $max_granularity) {
                 // Skip invalid combinations.
                 if (in_array($max_granularity, array('year', 'month', 'day')) && $tz_handling != 'none') {
                     continue;
                 }
                 $field_name = "field_test";
                 $label = 'Test';
                 $granularity = DateGranularity::arrayFromPrecision($max_granularity);
                 $options = array('label' => $label, 'widget_type' => 'date_popup', 'field_name' => $field_name, 'field_type' => $field_type, 'input_format' => 'custom', 'input_format_custom' => 'm/d/Y - H:i:s', 'tz_handling' => $tz_handling, 'granularity' => $granularity);
                 $this->createDateField($options);
                 $this->dateForm($field_name, $field_type, $max_granularity, $tz_handling);
                 $this->deleteDateField($label);
             }
         }
     }
 }
 /**
  * @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];
 }
 /**
  * Implements Drupal\field\Plugin\Type\Widget\WidgetInterface::settingsForm().
  */
 public function settingsForm(array $form, array &$form_state)
 {
     $field = $this->field;
     $instance = $this->instance;
     $widget = $instance['widget'];
     $settings = $widget['settings'];
     if (empty($settings['date_date_format'])) {
         $settings['date_date_format'] = variable_get('date_format_html_date', 'Y-m-d') . ' ' . variable_get('date_format_html_time', 'H:i:s');
     }
     $element = array('#element_validate' => array('date_field_widget_settings_form_validate'));
     $options = array();
     $formats = date_datepicker_formats();
     $example_date = date_example_date();
     foreach ($formats as $f) {
         $options[$f] = $example_date->format($f);
     }
     $element['date_date_format'] = array('#type' => 'select', '#title' => t('Date entry format'), '#default_value' => $settings['date_date_format'], '#options' => $options, '#description' => t('Control the order and format of the options users see.'), '#weight' => 3, '#fieldset' => 'date_format');
     $element['date_time_format'] = array('#type' => 'select', '#title' => t('Time entry format'), '#default_value' => $settings['date_time_format'], '#options' => $options, '#description' => t('Control the order and format of the options users see.'), '#weight' => 3, '#fieldset' => 'date_format');
     if (in_array($widget['type'], array('date_select', 'date_popup'))) {
         $element['year_range'] = array('#type' => 'date_year_range', '#default_value' => $settings['year_range'], '#fieldset' => 'date_format', '#weight' => 6);
         $element['increment'] = array('#type' => 'select', '#title' => t('Time increments'), '#default_value' => $settings['increment'], '#options' => array(1 => t('1 minute'), 5 => t('5 minute'), 10 => t('10 minute'), 15 => t('15 minute'), 30 => t('30 minute')), '#weight' => 7, '#fieldset' => 'date_format');
     } else {
         $element['year_range'] = array('#type' => 'hidden', '#value' => $settings['year_range']);
         $element['increment'] = array('#type' => 'hidden', '#value' => $settings['increment']);
     }
     $element['label_position'] = array('#type' => 'value', '#value' => $settings['label_position']);
     $element['text_parts'] = array('#type' => 'value', '#value' => $settings['text_parts']);
     $element['advanced'] = array('#type' => 'fieldset', '#title' => t('Advanced settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#fieldset' => 'date_format', '#weight' => 9);
     if (in_array($widget['type'], array('date_select'))) {
         $options = array('above' => t('Above'), 'within' => t('Within'), 'none' => t('None'));
         $description = t("The location of date part labels, like 'Year', 'Month', or 'Day' . 'Above' displays the label as titles above each date part. 'Within' inserts the label as the first option in the select list and in blank textfields. 'None' doesn't label any of the date parts. Theme functions like 'date_part_label_year' and 'date_part_label_month' control label text.");
     } else {
         $options = array('above' => t('Above'), 'none' => t('None'));
         $description = t("The location of date part labels, like 'Year', 'Month', or 'Day' . 'Above' displays the label as titles above each date part. 'None' doesn't label any of the date parts. Theme functions like 'date_part_label_year' and 'date_part_label_month' control label text.");
     }
     $element['advanced']['label_position'] = array('#type' => 'radios', '#options' => $options, '#default_value' => $settings['label_position'], '#title' => t('Position of date part labels'), '#description' => $description);
     $element['advanced']['text_parts'] = array('#theme' => $widget['type'] == 'date_select' ? 'date_text_parts' : '');
     $text_parts = (array) $settings['text_parts'];
     foreach (DateGranularity::granularityNames() as $key => $value) {
         if ($widget['type'] == 'date_select') {
             $element['advanced']['text_parts'][$key] = array('#type' => 'radios', '#default_value' => in_array($key, $text_parts) ? 1 : 0, '#options' => array(0 => '', 1 => ''));
         } else {
             $element['advanced']['text_parts'][$key] = array('#type' => 'value', '#value' => (int) in_array($key, (array) $settings['text_parts']));
         }
     }
     $context = array('field' => $field, 'instance' => $instance);
     drupal_alter('date_field_widget_settings_form', $element, $context);
     return $element;
 }
Exemple #5
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);
    }
}