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 both the 'publish on' and 'unpublish on' fields are filled in we should validate that the unpublication date is later than the publication date.
  • If the validation fails, display the following error message:

    The 'unpublish on' date must be later than the 'publish on' date.

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

Comments

joekers’s picture

Assigned: Unassigned » joekers
Status: Active » Needs review
StatusFileSize
new3.46 KB
joekers’s picture

StatusFileSize
new3.48 KB

Corrected comment.

The last submitted patch, 1: validate_that_the-2490580-1.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 2: validate_that_the-2490580-1.patch, failed testing.

jonathan1055’s picture

jonathan1055’s picture

Title: Validate that the unpublication date is later than the publication date » Validate that the unpublish date is later than the publish date

There was no automated test to check this validation, so I have added one to testValidationDuringEdit

✗	 testValidationDuringEdit
fail: [Other] Line 475 of modules/scheduler/src/Tests/SchedulerFunctionalTest.php:
Validation prevents entering an unpublish-on date which is earlier than the publish-on date.

As expected it currently fails.

jonathan1055’s picture

Status: Needs work » Needs review
StatusFileSize
new1.59 KB

Here's a re-rolled patch now that the constraint files are not new.

Status: Needs review » Needs work
jonathan1055’s picture

I was hoping to see testValidationDuringEdit all pass now but it does not, and we still have the same failure as before.

Can someone else test this patch? It works for me both interactive and in simpletest, so I do not understand why the test still fails on D.O. There was no error in applying the patch, at least I could not see any problem on https://dispatcher.drupalci.org/job/default/49316/console

jonathan1055’s picture

Status: Needs work » Needs review
StatusFileSize
new2.44 KB

Here's the same code change but with debug added. Hopefully this will indicate what might be happening on the DrupalCI which is different from my localhost.

Status: Needs review » Needs work
jonathan1055’s picture

Status: Needs work » Needs review
StatusFileSize
new2.74 KB

That's no help, I can't see where the debug output is, or maybe we only get debug written from the actual test files, and it is ignored from the real Scheduler functions. Here's a patch with the first constraint commented out, just to check that we are actually applying this patch correctly, as so far none of the recent patch tests above have had any obvservable impact on the result.

Status: Needs review » Needs work
jonathan1055’s picture

Something must be going wrong with the testbot patch process, as this recent patch had the working constraint commented out but the test still passed, ie the validation message must have been displayed, as no fail was given (see attached A). It seems that the tests are all being executed on un-patched code.

Also there was some major failure in the second test file SchedulerDateCombinedFunctionalTest (image attached B) which implies something going wrong which is nothing to do with our patches.

I think I will have to leave this, as can't see what more I can do. I will re-test tomorrow, to see if something has been fixed in DrupalCI.

jonathan1055’s picture

Same code as before, but re-rolled following recent commits. This should return all passes for testValidationDuringEdit() and overall we should get 10 classes pass and 6 fail.

Status: Needs review » Needs work

  • jonathan1055 committed 8113156 on 8.x-1.x authored by joekers
    Issue #2490580 by jonathan1055, joekers: Validate that the unpublish...
jonathan1055’s picture

Assigned: joekers » Unassigned
Status: Needs work » Fixed

That's good. Result as expected:

✓		- testValidationDuringEdit

10 class pass and 6 fail. Thanks Joe for the initial patch.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.