Updated: Comment #24
Problem/Motivation
There is one special date format name (not currently a real date format) that should be reserved: custom.
If someone creates a date format with a reserved name, fancy things will happen.
Proposed resolution
In the date format form for creation/edit we should disallow this "special" strings.
This is implemented by adding custom to the pattern, (not the exists, because custom technically does not exist, so that would have been a lie).
this issue is *not* fixing that there are formats that are not shown in the ui.
Remaining tasks
None
User interface changes
None.
but here is an example error.
API changes
None.
Related Issues
Subtask of #2052193: [META] Date format localisation is a huge mess, conflicts, does not work, regressed.
#2119903: Show locked date formats in the UI: Followup issue.
Comment | File | Size | Author |
---|---|---|---|
#24 | dateformat-dot.png | 209.49 KB | YesCT |
#24 | 2100351-23a-disallow-custom-fallback-name-date-format-do-not-test.patch | 5.11 KB | YesCT |
#24 | interdiff-21-23a.txt | 950 bytes | YesCT |
#24 | 2100351-23b-disallow-custom-fallback-name-date-format.patch | 4.87 KB | YesCT |
#24 | interdiff-23a-23b.txt | 5.07 KB | YesCT |
Comments
Comment #1
grisendo CreditAttribution: grisendo commentedPatch attached.
Comment #2
grisendo CreditAttribution: grisendo commentedWorking on test.
Maybe it should be good to specify somewhere that 'custom' and 'fallback' are not allowed, and try to change error messages on that cases.
But not sure where to inform (#description ?), and which messages to show.
Comment #3
grisendo CreditAttribution: grisendo commentedComment #4
grisendo CreditAttribution: grisendo commentedTests added. I think interdiff is not needed as here since only test is added, no other changes.
Comment #5
grisendo CreditAttribution: grisendo commentedOops, bad file for "only-test.must-fail" patch. Here are the good ones.
Comment #6
penyaskitoAwesome work!
Some naming stuff needs more work:
This is checking for disallowed machine names, not for allowed machines names.
Should be renamed to something like "isInvalidMachineName".
The key in this array should be changed to something according to the new validation?
Comment #7
grisendo CreditAttribution: grisendo commented1. Oops, you are right :) bad naming there.
2. Don't know exactly if I understand. Word 'exists' is a reserved "parameter" for '#machine_name' field type. Nothing to do here I think.
Thanks!
Comment #9
grisendo CreditAttribution: grisendo commented#7: 2100351-disallow-custom-fallback-name-date-format-07.patch queued for re-testing.
Comment #10
grisendo CreditAttribution: grisendo commentedLet's try this one...
Comment #12
grisendo CreditAttribution: grisendo commentedOops, wrong patch in #10, not for here... too much sprinting :(
Comment #14
herom CreditAttribution: herom commentedThis should be "needs review". and the patch to review is at #7.
Comment #15
Gábor HojtsyReviewed #7. Not bad, not bad :) :)
"Checks if a machine...."
The wording here is not very nice IMHO. Eg. "Date formats" in the name IMHO because this is not a module name or some other concrete thing. No good suggestion for the description, but it does not feel 100% right either.
These asserts should assert the text with t().
This looks a bit strange. I see it is supposed to be bulletproof but a 16 long random string will *never* equal 'custom' or 'fallback', neither of which are 16 characters long. So no need for the do/while.
Comment #16
pfrenssenComment #17
Gábor HojtsyLooks much better. RTBC if green as far as I'm concerned.
Comment #18
alexpottThe problem is the error message makes no sense :(
Since when I go to the list of data formats I don't see a fallback or custom date format listed.
Comment #19
Gábor HojtsyIf so that is an existing problem:
You don't see most of these on the page either (including fallback). So the same happens before/after this patch. In fact if this patch needs work, that sounds like it would be because fallback is already an existing entity, so we don't need to special case it, we only need to special case custom.
The ones that don't show up on this screen are locked and not editable. They do exist anyway.
Comment #20
Gábor HojtsySo retitling since 'custom' is the only one that needs special casing.
Comment #21
Gábor HojtsyMade those changes. Should be back to RTBC then.
Comment #22
alexpottUnfortunately
system.date_format.custom.yml
still actually does not exist though so the error message is misleading.So reading the form_process_machine_name() code I don't think we should be futzing with the exists function. I think we should be providing a custom replace pattern that will produce a custom error message that informs the user that custom is a reserved word.
So
becomes something like
Comment #23
YesCT CreditAttribution: YesCT commentedI'm working on this.
Comment #24
YesCT CreditAttribution: YesCT commentedfirst interdiff to 23a is just docs cleanup for #338403: Use {@inheritdoc} on all class methods (including tests)
second interdiff does what @alexpott asked for in #22
and takes out an unrelated change reordering the use statements.
adds a test for invalid pattern, since now we added that to date format machine names we need to test it specifically for date format.
only patch b needs to be run on the testbot.
example:
Comment #25
Schnitzel CreditAttribution: Schnitzel commentedlooks good! like this approach also much better :)
Comment #26
Gábor HojtsyThis is not related to solving anything for the language system it is just a bug found on the way, so removing the D8MI tags.
Comment #27
ursula CreditAttribution: ursula commentedOpened a follow up issue proposing to display reserved machine names and formats on the UI:
#2119903: Adding date format returns error for format not in the date-time list
Comment #27.0
ursula CreditAttribution: ursula commentedUpdated issue summary.
Comment #27.1
ursula CreditAttribution: ursula commentedissue summary: removed remaining task
Comment #28
pfrenssenVery nice solution, I like it :)
Comment #29
webchickThe only thing that seemed a bit weird to me was that these awesome tests are specific to date formats. Seems like this is actually testing the underlying machine name code moreso than date formats specifically.
However, that is something we could always clean up in a follow-up, and this patch looks straight-forward enough to fix this particular issue. Great work!
Committed and pushed to 8.x. Thanks!
Comment #30
Gábor HojtsyYay, thanks all!
Comment #30.0
Gábor HojtsyIssue summary update