- πΊπΈUnited States smustgrave
Since there hasn't been a follow up to #13 going to close for now.
If still an issue please reopen updating the issue summary as needed.
Thanks!
When trying to implements an #element_validate callback on the start date element of a Date Range field :
$form['field_candidates_unavailability']['widget'][0]['value']['#element_validate'][] = [$this, 'validateUnavailabiltyDates'];
I get a "This value should be of the correct primitive type." error on validation. The value has not been modified, just a simple diff test with the today date :
$start_value = $form_state->getValue('field_candidates_unavailability');
/** @var \Drupal\Core\Datetime\DrupalDateTime $start_date */
$start_date = $start_value[0]['value']['object'];
$today = new DrupalDateTime('now', drupal_get_user_timezone());
datetime_date_default_time($today);
$diff = $today->diff($start_date);
if ($diff->days == 1 && $diff->invert == 1) {
// Start date is anterior to today, throw an error.
$form_state->setErrorByName(implode('][', $element['#parents']), 'The start date must be posterior to today.');
}
I can see that PrimitiveTypeConstraintValidator::validate method get an array for the field $value, instead of a date in string format.
I've to do this weird trick in the #element_validate callback to make this PrimitiveTypeConstraintValidator works :
$form_state->setValue($element['#parents'], $start_value[0]['value']['date']);
Closed: outdated
11.0 π₯
Last updated
The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
Since there hasn't been a follow up to #13 going to close for now.
If still an issue please reopen updating the issue summary as needed.
Thanks!