Problem/Motivation
On admin/config/regional/date-time/formats/add only the Format string field has the required label the name field is missing that. if you fill out only the format string and language select box and save the required machine readable name field shows up.

It is the same for /admin/structure/display-modes/form/add and /admin/structure/display-modes/view/add.
Steps to reproduce
- go to admin/config/regional/date-time/formats/add
- add something to the format string field eg m/d/Y - h:i a
- set the language in the select box and save
- now enter something in the name field -> the entry isnt added to the machine readable name as well in that state
- clear the name field again and enter something in the machine readable name field and save instead.
- edit the date format with no name. the machine readable name field isnt shown as a field anymore but as a string as usual.
Proposed resolution
I've created an initial merge request adding '#required' => TRUE to the $form['label'] fields in entitydisplaymodeformbase.php and dateformatformbase.php. more or less all other name/label fields in Core adding anything have the name/label field required. by requiring it is ensured the name field is filled and that way the at first invisible machine name field gets populated accordingly.
Remaining tasks
I am not sure if it would be necessary to add tests as well, i am not a developer and never dealt with tests before.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 3273102-9.patch | 2.04 KB | smustgrave |
| #9 | 3273102-9-tests-only.patch | 949 bytes | smustgrave |
Issue fork drupal-3273102
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
rkollerComment #4
rkollerComment #6
rkollerand i'll set the issue to needs review. as noted in the issue summary i am not a developer and therefor not sure if a test is needed and in case it is how to write one (never done that).
oh and i notice initially the scope of the issue was about the date format but now got extended to the form mode and view mode as well. not sure if the component language system is the right fit anymore or if it was in the first place at all. :/ please change the component accordingly. thank you.
Comment #7
sonam.chaturvedi commentedVerified and tested he MR !2685. Patch applied successfully on 9.5.x-dev.
Test Steps:
1. Goto admin/config/regional/date-time/formats/add
2. Check 'name' field is required.
3. Add something to the format string field eg m/d/Y - h:i a
4. Set the language in the select box and Save
5. Date format should be added successfully.
6. Repeat step 2 for /admin/structure/display-modes/form/add and /admin/structure/display-modes/view/add.
Test Results:
'name' field is required for :
1. /admin/config/regional/date-time/formats/add
2. /admin/structure/display-modes/form/add
3. /admin/structure/display-modes/view/add
Before patch:

After patch:


Comment #8
smustgrave commentedWill need a test case.
Comment #9
smustgrave commentedHere's a tests-only patch and a copy of the MR + the test. Can move that test into the MR if you like. I only uploaded it so when the tests-only fails it doesn't move the ticket back to NW.
Comment #11
rkolleroh thanks for the test! awesome that way i guess i was able to slightly grasp how things are intended to work. about the changes in #9 two questions.
1) is it correct that
$this->assertSession()->elementAttributeExists('css', '#edit-date-format-pattern', 'required');wasn't directly part of the issue but it looks like a test for that date format required pattern was missing so you have just added it along the way? (*that is just a question for my own understanding)2) i guess the field in the
field_uimodule also needs a test for the required field inEntityDisplayModeFormBase.php? are the functional tests for that placed inEntityDisplayModeTest.php? based on the tests inDateTimeTest.phpi would guess either one or both of the following code blocks have to be added?or would be one of the two enough because they are based on the same file? or is it the other way around and every
addcase path has to be called withdrupalGetline?and about the how to proceed i dont mind. we could either stay with patches if it is easier that way or move everything into the MR. however you prefer. i'll set the issue to needs work. in case question 2 applies then the test has to be added but if not the issue could be set to RTBC i suppose? cuz the patch in #9 applied cleanly.
Comment #12
smustgrave commented#11.1 that's correct. I couldn't find where it was testing that field was required also so added that test coverage
#11.2 Not sure about the field_ui. My understanding was this fix was directly for the add date format page.
You don't have to add drupalGet if you are staying on the same page while testing.
We can add back to the MR. The comment should probably be updated to "Verify name and format fields are required"
Only reason I added them as a patch was to get that red/green pattern. So the tests prove that your MR changes will fix the problem. I just haven't figured the best approach to get that red/green with MR yet.
Comment #13
rkoller#11.1 thanks for the confirmation and good choice
#11.2 the initial issue title, scope and report was about the date format page. but then i've realized when going through the add forms on a site again that there were more occasion and it applies to the form and view mode add pages as well, so i've rephrased the issue title and scope in #4 plus updated the issue summary.
well for the add pages for form modes you dont have a single page. you have:
and the same amount of different pages for view-mode add pages. but each of the sixteen pages is based on
EntityDisplayModeFormBase.php. thats why i've asked how to handle that case. if onedrupalGetwould be enough, if onedrupalGetfor display and one drupalGet for form mode add page would necessary, or each of those sixteen pages has to get adrupalGet?and i agree about updating the comment including the format field.