Problem/Motivation
When adding a node or taxonomy term with a "Url Alias" that already exists the error message "The alias is already in use." is displayed but the 'error' CSS class is not applied to the 'alias' element. This is because path_form_element_validate does not send correct $name parameter to form_set_error.
Proposed resolution
Change path_form_element_validate to call form_set_error with correct $name parameter
From
if ($query->execute()->fetchField()) {
form_set_error('alias', t('The alias is already in use.'));
}
to
if ($query->execute()->fetchField()) {
form_set_error('path][alias', t('The alias is already in use.'));
}
This cause the element to have the 'error' CSS class.
Patch coming...
Original report by tedbow
Comments
Comment #1
tedbowAttaching patch
Comment #2
Niklas Fiekas commentedWhen we have $element available anyway, we should rather use form_error(), as in this example: http://api.drupal.org/api/drupal/developer--topics--forms_api_reference....
Comment #3
Niklas Fiekas commentedAlso against 8.x first, then backport.
Comment #4
tedbowOk, I have attached the D8 patch using form_error instead form_set_error.
Thanks for the help.
Comment #5
Niklas Fiekas commentedThank you. The patch looks good and solves the problem.
Comment #6
tedbowNo problem. Glad I could finally give something back(however small) to core : )
Should submit a new D7 patch here or would that a new issue?
Comment #7
Niklas Fiekas commentedYou could already prepare a 7.x patch and upload it. Since it will fail the automated testing when tested in an 8.x issue, you could name it something-d7.patch, so that it will be ignored by the testbots.
We also have a "patch (to be ported)" issue status that is used when an issue has been fixed but no backport is available by then, so that no new issue must be created.
Comment #8
tedbowThanks for explanations. I have attached the D7 patch.
Comment #9
catchThanks for the patch. We should write an automated test for this though before committing.
Comment #10
Niklas Fiekas commented@tedbow: Should I do that, or do you want to write a test case? Do you need help there?
Comment #11
tedbow@Niklas Fiekas would I write a test that tries to use the same alias twice and then test the html response to see that html element has the "error" class applied? If so could you point me to an existing test that submits a form and checks html response?
Thanks for your help
Comment #12
Niklas Fiekas commentedHave a look at:
from the example module: http://drupalcode.org/project/examples.git/blob_plain/refs/heads/8.x-1.x....
This is a real world example from the core test suite:
http://api.drupal.org/api/drupal/modules--node--node.test/function/PageE.... Click "View source" at the bottom of http://api.drupal.org/api/drupal/modules--node--node.test/class/PageEdit... for the full test case class.
Comment #13
tedbowThanks, a lot. 1 other question should the test be added to the original patch. Or should they be separate?
Comment #14
Niklas Fiekas commentedBoth, probably. Just the testcase, so that we see the problem actually exists - we're expecting that test to fail. And a combined patch, that should pass. The latter will get comitted, eventually.
Comment #15
Niklas Fiekas commentedTo push this forward: Here's a test that fails without the fix and should pass with tedbow's fix.
Comment #16
tedbowNiklas Fiekas, Thanks for doing this, got sidetracked on another project. I will also watch and to make sure 2nd patch works.
Comment #17
tedbowNiklas Fiekas, Looks like the test with patch worked. Does anything else need to happen with this?
Comment #18
Niklas Fiekas commentedYeah ... it needs to be reviewed. Set it back to "needs work" when you find coding style issues or something doesn't work as expected. Someone who didn't yet work on this can also mark it as "reviewed & tested by the community" when everything looks good. That is the last step before committing.
Comment #19
xjmI had to read this a couple times to understand it; I'd suggest:
Looks good other than that. Thanks!
Edit: Screenshots and manual testing might be a good idea for this issue, too.
Comment #20
Niklas Fiekas commentedOk, thanks for reviewing.
Doxygen reworded, these are the screenshots:


(before)
(after)
Comment #21
xjmThis looks great to me. (I'm assuming tests will pass; the queue is a bit backed up.) Thanks @Niklas Fiekas and @tedbow!
Comment #22
webchickGreat little bug fix, great little test! :)
Committed and pushed to 8.x and 7.x. Thanks!