By Free Radical


2019-05-12 16:07:02 8 Comments

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.

0 comments

Related Questions

Sponsored Content

3 Answered Questions

[SOLVED] How do I extract filename and filepath from a file field?

1 Answered Questions

1 Answered Questions

[SOLVED] Paragraphs item doesn't load on node/add

  • 2016-07-24 17:33:48
  • thejimbirch
  • 433 View
  • 0 Score
  • 1 Answer
  • Tags:   7

1 Answered Questions

[SOLVED] After upgrading, the Search module gives no results

  • 2014-11-17 16:29:00
  • tenken
  • 348 View
  • 1 Score
  • 1 Answer
  • Tags:   7 upgrading

0 Answered Questions

Errors while creating Drupal Commerce product programmatically

  • 2016-04-07 06:57:10
  • dreamy79
  • 108 View
  • 1 Score
  • 0 Answer
  • Tags:   7 drupal-commerce

4 Answered Questions

[SOLVED] I get image field upload errors with a custom node_add() form

  • 2012-05-11 22:27:58
  • emc
  • 2029 View
  • 0 Score
  • 4 Answer
  • Tags:   7 forms ajax media

1 Answered Questions

Help with debugging and fixing errors with SalesForce Mapping Module

  • 2015-03-04 23:40:57
  • jtrenton
  • 208 View
  • 1 Score
  • 1 Answer
  • Tags:   7 crm

4 Answered Questions

[SOLVED] Custom theme doesn't show up in Blocks section

  • 2012-07-06 01:05:01
  • Pollux Khafra
  • 3024 View
  • 1 Score
  • 4 Answer
  • Tags:   7 blocks

1 Answered Questions

[SOLVED] Using Rules to Update the Data of a Relations Endpoints (Referenced Entities)

  • 2012-12-28 01:14:10
  • jhoffmcd
  • 422 View
  • 0 Score
  • 1 Answer
  • Tags:   7 rules entities

Sponsored Content