When saving a form with the Office Hours fields that contains a value of "0300" (which represents 12:30 AM), the error "This value should be of the correct primitive type." appears for the start time of "00:30".
The module currently defines the starthours and endhours fields as integers, as follows:
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['day'] = DataDefinition::create('integer')
->setLabel(t('Day'))
->setDescription("Stores the day of the week's numeric representation (0-6)");
$properties['starthours'] = DataDefinition::create('integer')
->setLabel(t('Start hours'))
->setDescription("Stores the start hours value");
$properties['endhours'] = DataDefinition::create('integer')
->setLabel(t('End hours'))
->setDescription("Stores the end hours value");
return $properties;
}
The custom Office Hours validation first runs, followed by the Drupal core validations. Within Drupal's core validations, the PrimitiveTypeConstraintValidator validation fails because a time of "0300", which represents 12:30 AM, is not an integer, but rather a string.
To fix, the data definition for the time fields need to be defined as strings so they are validated as such by Drupal core. The required change is as follows:
$properties['starthours'] = DataDefinition::create('string')
...
$properties['endhours'] = DataDefinition::create('string')
...
This change does not change how the office hour start and end times are calculated and stored in the database.
Comment | File | Size | Author |
---|---|---|---|
#3 | 2850486-3.patch | 1.34 KB | casey |
#2 | 2850486-primitive_type_error_for_start_time_of_0030.patch | 931 bytes | sbreese |
Comments
Comment #2
sbreese CreditAttribution: sbreese as a volunteer commentedComment #3
casey CreditAttribution: casey at SWIS commentedOr we could just cast the form inputs to ints during massageFormValues().
Comment #4
johnvComment #5
johnvComment #6
johnvComment #8
johnvI committed a fix using casey's approach. Part of the code went into OfficeHoursWidgetBase:massageFormValues(), because the error appease both on both available widgets ('Week' and 'List').
Thanks.