Problem/Motivation
If a custom language is submitted and doesn't pass the form validator an undefined index errors occurs:
Notice: Undefined index: langcode in language_admin_edit_form_validate() (line 365 of core\modules\language\language.admin.inc).
may only contain characters a-z, underscores, or hyphens.
Notice: Undefined index: name in language_admin_edit_form_validate() (line 368 of core\modules\language\language.admin.inc).
cannot contain any markup.
Proposed resolution
Reason for this issue is that language_admin_add_custom_form_validate() reuses language_admin_edit_form_validate().
To do so it passes its own form array to the other function - but in this form array the necessary values are located in the child container 'custom_language'.
To get around this I propose to simply pass the child container to language_admin_edit_form_validate() instead the whole form.
The attached patch contains the fix as well as new tests for this issue.
Remaining tasks
reviews needed
User interface changes
None
API changes
None
Comments
Comment #1
vasi1186 commentedJust a small thing:
Shouldn't we use t() here? As I've seen, t() is usually used to check the messages in the core tests.
Comment #2
das-peter commentedAdded
t()functions and rewritten some assertions to properly use the already usedt().Comment #3
vasi1186 commentedLooks good, found just some really small things after a closer look:
This is better, but I actually think that the 100% correct version would be to use the t() also on the 'Language code', 'Language name' etc... This is because the core uses the #title attribute, which in our case is t('Language code'), etc...
The same as above.
I think here we do not have to use the t() on $edit['name'] and $edit['langcode'].
Comment #4
das-peter commentedThanks for the review.
I would love to be able to use a generic way to use the field titles, could make the usage of
t()obsolete and the tests would be still valid if just the titles of the fields change.Any ideas?
However, patch is adjusted :)
Comment #5
vasi1186 commentedI think you missed this one :)
and this one. Here, we should not have t().
Otherwise, everything looks good to be, after uploading the new patch, and the testbot is green, can be RTBC.
Comment #6
das-peter commentedHere we go, sorry for being sloppy :|
Comment #7
vasi1186 commentedLooks good now to me, if green tests, it is RTBC from my side.
Comment #8
pp commentedI review a patch. I check "User interface translation" - "Import" page (admin/config/regional/translate/import) because you can add new language there. I saw you can not add custom language. So, I can't reproduce this bug there.
The patch looks good for me too.
Comment #9
pp commentedComment #10
webchickA few minor things, but enough of them that I don't really feel comfortable editing prior to commit.
"Create user with permissions to add and remove languages."
That second comment should be moved to just above the assertText() stuff.
Assertion messages should not be wrapped in t(). It should just be 'Correct page redirection' rather than t('Correct page redirection')
This needs to be changed to "of" rather than "off"
(nit-pick) We should add newline between these.
"...and confirm that this is not allowed." or something, to provide some context as to why you would want to do that. :)
Comment #11
das-peter commentedThanks for the feedback. Attached the re-rolled patch and the interdiff.
Comment #12
webchickOn visual inspection this looks like what I asked for, thanks! There are a couple of minor things like whitespace that I can clean-up on commit.
Moving to RTBC and we'll see what the testbot thinks.
Comment #14
das-peter commented#11: language-undefined-index-in-custom-language-form-1751082-11.patch queued for re-testing.
Comment #16
das-peter commentedHmm, looks really like something with the behaviour of the radios form element type changed during my re-roll.
I'm unable to provoke an empty radios value for the language direction field. Thus I can't test it anymore - I've now simply removed the assertion.
Comment #17
vasi1186 commentedThose radio buttons from what I remember it used to not have a default value for a new language, but I think some patch that was committed recently has changed that. If you check the _language_admin_common_controls() function, you can see that, if a language is not sent as a parameter, then a default Language object is created. The Language class has as the default parameter for the direction the value LANGUAGE_LTR. The radio buttons will (or at least should) always have a default value, and probably this is why you do not get the error message anymore on the page.
So, maybe now it would make sense to test that the selected radio button by default is LANGUAGE_LTR (or even better, to check that the selected radio button is the default direction parameter of the Language class).
After that, and the test bot returns green, can be set to RTBC again.
Comment #18
das-peter commentedI was really tempted to remove all this assertions since it starts to look like I'm testing the Form-API.
And now even the assertion for the direction looks somehow odd...
Comment #19
vasi1186 commentedWell, yes, maybe you're right, probably the test class makes more tests than the ones strictly related to the issue. But, from my point of view, this is not a harmful thing, and is better than having less tests than it should. So, from my side, can be RTBC.
Comment #20
catchNo need to document the getInfo() method. Otherwise this looks fine to me. The tests for page redirection do look a bit odd but I agree they're not doing any harm.
Comment #21
das-peter commentedI re-rolled the patch but I'm unsure about
No need to document the getInfo() methodthere's this discussion ongoing: #338403: Use {@inheritdoc} on all class methods (including tests)An drupalcs currently reports
25 | ERROR | Missing function doc commentIf there's no chance of having soon a decision on #338403: Use {@inheritdoc} on all class methods (including tests) I might should change the drupalcs sniff.
I'm bold and set this right away back to RTBC (it's really just the change as shown in the interdiff ;) ) - please correct me if this is wrong.
Comment #22
webchickCommitted and pushed to 8.x. Thanks!
Comment #23
gábor hojtsyRemoving from sprint. I don't think this should get a changelog entry or change notice, it is just fixing a bug introduced in D8 :) Thanks all though!