1

The Date module provide a field type called date_combo that allows a date feld to collect both a start date and an end date.

It works as expected when I use the GUI to create a content type with a date field an tick the box for the field setting saying: "Collect an end date" (i.e. you get an extra date field for the end date on the form to create new content).

I want to use the the date_combo content type when I construct a form using the Drupal API. So far, I've inspected the form that is created by the GUI, and tried to duplicate this. But I am getting errors complaining about undefined indices in the form. For example:

Notice: Undefined index: #field_name in date_combo_element_process() (line 259 of .../sites/all/modules/date/date_elements.inc).
Notice: Undefined index: #bundle in date_combo_element_process() (line 261 of .../sites/all/modules/date/date_elements.inc).
Notice: Undefined index: #entity_type in date_combo_element_process() (line 262 of .../sites/all/modules/date/date_elements.inc).
Notice: Undefined index: #language in date_combo_element_process() (line 263 of .../sites/all/modules/date/date_elements.inc).
Notice: Undefined index: #field_parents in field_widget_field() (line 577 of .../modules/field/field.form.inc).

This is what I've tried so far:

  $form['datepair']['arrdep'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'class' => array(
        0 => 'field-type-datestamp',
        1 => 'field-name-rbg-unixtime',
        2 => 'field-widget-date-text',
      ),
    ),
    '#weight' => 1,
    '#tree' => TRUE,
    '#language' => LANGUAGE_NONE,
    LANGUAGE_NONE => array(
      0 => array(
        '#entity_type' => 'node',
        '#bundle' => 'rbg_booking',
        '#field_name' => 'field_rbg_unixtime',
        '#language' => LANGUAGE_NONE,
        '#field_parents' => array(),
      ),
      '#entity_type' => 'node',
      '#bundle' => 'rbg_booking',
      '#field_name' => 'field_rbg_unixtime',
      '#language' => LANGUAGE_NONE,
      '#field_parents' => array(),
    ),
    '#entity_type' => 'node',
    '#bundle' => 'rbg_booking',
    '#field_name' => 'field_rbg_unixtime',
    '#field_parents' => array(),
    '#access' => TRUE,
    'arrdep' => array(
      '#title' => t('A pair of dates:'),
      '#description' => t('Description'),
      '#type' => 'date_combo',
      '#theme_wrappers' => array(
        0 => 'date_combo',
      ),
      '#size' => 8,
      '#default_value' => array(
        'value' => $date,
        'value2' => $date2,
        'timezone' => 'UTC',
        'timezone_db' => 'UTC',
        'data_type' => 'datestamp',
      ),
      '#date_timezone' => 'UTC',
      '#element_validate' => array (
        0 => 'date_combo_validate',
      ),
      '#date_is_default' => TRUE,
      '#date_items' => array(
        'value' => $date,
        'value2' => $date2,
        'timezone' => 'UTC',
        'timezone_db' => 'UTC',
        'data_type' => 'datestamp',
      ),

    ),
  );

Guidance regarding how to make use of he date_combo construct by means of the Form API will be much appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.