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.

CommentFileSizeAuthor
#2 Screen Shot 2015-11-14 at 16.51.55.png9.35 KBjoekers
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joekers’s picture

Assigned: Unassigned » joekers
joekers’s picture

Not 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.

jonathan1055’s picture

Hi Joe,

I don't think the date format from the Scheduler settings is used when creating the publish_on and unpublish_on dates

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.

joekers’s picture

I 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.

jonathan1055’s picture

jonathan1055’s picture

jonathan1055’s picture

Assigned: jonathan1055 » Unassigned
Status: Postponed » Closed (works as designed)

The 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