Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In Drupal 7 we implemented hook_node_validate()
to validate the scheduling fields when a node form is submitted. In Drupal 8 this should be done using validation constraints.
- If the 'publish on' field is filled in we should validate whether the entered date corresponds to the configured date format.
- If the validation fails, display the following error message:
The 'publish on' value does not match the expected format of %time
- Also remove the corresponding lines from
scheduler_node_validate()
.
See change record: Entity level validation constraints can be added and the documentation page for the Entity Validation API.
Comment | File | Size | Author |
---|---|---|---|
#2 | Screen Shot 2015-11-14 at 16.51.55.png | 9.35 KB | joekers |
Comments
Comment #1
joekersComment #2
joekersNot sure if we need this validation still as Drupal has it's own validation as a part of the widget. Also I don't think the date format from the Scheduler settings is used when creating the publish_on and unpublish_on dates.
Comment #3
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedHi Joe,
So what happens if the date entry is just a plain text entry field? I think we should be insisting that the text matches the required format, if only for avoiding mistakes which might still be valid dates, such as entering 2015-05-10 which could be 5th October or 10th May, if we did not check against our desired format.
Comment #4
joekersI couldn't test with a plain text field as I think it's only used on older browsers without HTML5 support. The default Datetime Timestamp widget provided by Drupal doesn't seem to use the format we set in the Scheduler - maybe we need to extend it so we can use our format and then check it in the validation constraint.
Comment #5
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedComment #6
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedPostponed. This validation may be removed depending on the outcome of #2799869: Date field placeholder text doesn't reflect date format defined in admin settings - hardcode the format
Comment #7
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedThe validation is no longer required now that the format is not configurable - see #2799869: Date field placeholder text doesn't reflect date format defined in admin settings - hardcode the format