I have an ajax callback on my date field that changes a particular field when user chooses a date.
Here is my code:
// INSIDE FORM_ALTER
$ form['field_camp_scheduled_time']['widget']['#options'] = populate_scheduled_time($ form, $ form_state);
//THE METHOD
function populate_scheduled_time($ form, $ form_state){ $ date = $ form_state->getValue('field_camp_scheduled_date')[0]; }
As you can see from the method above, I’m trying to get the value of the date field. But instead of getting the date ‘2018-26-01’, I’m getting an array:
Drupal\Core\Datetime\DrupalDateTime Object ( [formatTranslationCache:protected] => [inputTimeRaw:protected] => [inputTimeAdjusted:protected] => [inputTimeZoneRaw:protected] => [inputTimeZoneAdjusted:protected] => [inputFormatRaw:protected] => [inputFormatAdjusted:protected] => [langcode:protected] => en [errors:protected] => Array ( ) [dateTimeObject:protected] => DateTime Object ( [date] => 2018-01-27 12:00:00.000000 [timezone_type] => 3 [timezone] => UTC ) [stringTranslation:protected] => )