Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
field system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
6 Nov 2015 at 07:17 UTC
Updated:
31 Mar 2016 at 12:34 UTC
Jump to comment: Most recent, Most recent file

Comments
Comment #2
tstoecklerI am pinging @tassilogroeper to comment here, because he discovered the issue and should be credited.
Attached patch fixes the issue.
This results in a pretty weird label in the details element, however.
This is due to following code in Configuration Translation's
ListElement(simplified here for readability's sake):The element uses the first element that it finds that contains either
titleorlabelin its name, and in this case it findson_label. This code was intended for things like Views, where you have multiple displays inside of the view, and Configuration Translation wants to display the title of each display instead of just printing Views display for each one, which would make it near impossible to sensibly translate the view. In this case, however, this backfires a little, so not sure if and - if so - how we want to adapt this.Comment #3
tstoecklerAhh, here's the patch.
Comment #4
tstoecklerOh, this, as always, needs tests.
Comment #5
penyaskitoMarking as needs work as it needs tests.
I couldn't find a test for the current behavior for "Configuration Translation wants to display the title of each display instead of just printing Views display for each one".
We should probably add one for that so we are sure we don't break that feature.
Comment #6
tassilogroeper commented+1 nice work. thanks @tstoeckler
Comment #7
tstoecklerI started some work on fixing the issue with the labels on the config translation form. I had previously thought that the code referenced in #2 is for contrib that does not name its elements
titleorlabeldirectly, but in fact we have that use-case in core already with views: The label/title of views displays is available under adisplay_titlekey, which is why that generic/catch-all code is needed, or at the very least outright removing it results in a regression.I also though the logic in
\Drupal\config_translation\FormElement\ListElement::getGroupTitle()could be simplified to always have a title using the schema key as a last-resort fallback, but I realized we cannot do that either, because from the schema we have no way of differentiating between "static" mappings, i.e. where a mapping consists of X known keys, no more, no less, and "dynamic" mappings, i.e. where a list of views displays is contained and any number of keys can appear. We only need the logic ofgetGroupTitle()in the latter case but because there is no way to differentiate it is called in both cases, so we need the empty handling for the former case.So no code to show yet...
Comment #8
tstoecklerSomething like this.
This comes with tests for the views display labels on the config translation form. It still needs tests for the boolean field itself but - more importantly - we need to carefully vet all config translation forms if there are more cases like views where we have keys that contain "title" or "label" in core. Then we also need to get some feedback from a maintainer, whether this minor API change is feasible for 8.0.x. Not tagging "Needs maintainer feedback", though, because we first need to update the issue summary to clearly explain the situation. Therefore tagging "Needs issue summary update" instead.
I think it's of pretty big importance to get this in 8.0.x so in case this is not deemed possible for 8.0.x we should consider a more workaround-y solution that does not involve an API change at all. I.e. have the boolean field schema add a "don't try to be smart here about the labels" flag (just with a better name) that we use in
getGroupTitle()to avoid the magic behavior. That would be a pure API addition.Comment #9
tstoecklerComment #10
vijaycs85Are we sure to strip tags here?
Do we need this here? Looks like not in scope of this issue.
Comment #11
gábor hojtsy@vijaycs85: re 2, looks like we need to do that change so we can test it (or at least we need to add it to a test schema to test it there, but then we need to fix it in views too as per above).
@tstoeckler: I think the API addition implemented here is entirely backwards compatible, so it should not be considered an API change. API additions should be possible in 8.1, not earlier though AFAIK. We may want to get the schema fix for string => label in ASAP, even if the UI is a bit confusing, at least the translatability would be there and the API addition for 8.1 AFAIS.
Comment #12
badrange commentedI just stumbled across this issue in a customer site - this time when adding a boolean to a contact form (using Core contact module). After applying the patch I was able to translate the boolean value labels, export the configuration, move it to a dev server with the patch - and the translation came along. Happy times!
Thanks for making this patch - now I'm hoping it can enter in a future 8.0.x so that also people who don't go hunting in the issue queue for patches can translate their labels..
Comment #13
badrange commentedA colleague tipped me about this issue:
https://www.drupal.org/node/1061438
Are these duplicate of one another?
Comment #14
mikeker commentedDespite predating this issue by four and a half years, I'm closing #1061438: "On" and "Off" values for boolean fields are not translatable as a dup of this because the patch here has tests and the patch there wasn't approaching the fix correctly.
Comment #15
gábor hojtsy@mikeker: well actual tests for the actual fix are still missing. Can you help provide them? :) I think that is mostly what separates us from this being comittable.
Comment #16
kristen polThanks for the patch. I noticed one typo:
Nitpick (typo): uniqiue => unique.
Comment #17
tstoecklerPer #11 here's a patch with just the schema change + test coverage. Will open a new issue for the label improvements including the views test coverage.
@Kristen Pol: Thanks for the review! I will make sure it does not get lost when I open the new issue.
Comment #18
tstoecklerComment #20
kristen polThanks! I looked at the new patch and have one question:
Is there supposed to be an assertText for $off_label too?
Comment #21
kristen polOh... I see, it's the fieldset so I guess not. That is a bit confusing.
Comment #22
kristen polI think it would be useful to add some comments to explain what is being checked, particularly for the assertText part. Thanks.
Comment #23
tstoecklerThanks for the review! #22 is a very good point. Will do that once I have opened the other issue, so we can add a @todo to that in the code.
Comment #24
kristen polI have tested the patch and it is working as expected.
Comment #25
kristen polFor better UX though, I'm wondering if it would be make sense to get rid of the fieldset altogether?
Comment #26
gábor hojtsy@Kristen: for config translation, the fieldset is merely there because the two labels are contained within a parent element. This is automated and cannot be overridden in core at least. I think this is already a big enough improvement either way?
Looking at the summary, it seems to be updated according to current patch.
Comment #27
kristen pol@Gábor Hojtsy - Ok, no worries. Yes, this is a great improvement! :) RTBC++
Comment #30
alexpottCommitted 5830c2f and pushed to 8.0.x, 8.1.x and 8.2.x. Thanks!
Comment #32
alexpottComment #36
alexpottThis patch caused a random fail... https://www.drupal.org/pift-ci-job/214169
I don't think there is any reason to use
->randomString()here... how about just hardcoding values?Comment #37
alexpottAnd here... https://www.drupal.org/pift-ci-job/214193
Comment #38
tstoecklerThat's fine with me. I had copied the method from the test method above and adapted it. That is the only reason why there was randomString() in there.
Comment #39
alexpottHere's 20 runs of the test... the first string is the on label and the second is the off label.
So the problem seems to be related to spaces...
Comment #40
tstoecklerWow, that's very useful, thanks a lot! Will look into it...
Comment #41
mikeker commentedChanged the on/off labels to be fixed strings instead of
randomString(). I still can't figure out what about those strings was causing the failure, though. Also added two comments to better describe what's being tested, as per #22.Comment #42
kristen polThanks for the update. I think it's useful that you added more comments.
Nitpick: For this one, maybe something like the following would be more clear?
// Checks the fieldset text.The other ones look good to me.
Comment #43
tstoecklerThanks for the patch!
Can we add some markup such as & and < > to the test strings? I *think* those will force to go back to using assertEscaped(), but we'll see about that.
Comment #44
mikeker commented@tstoeckler: Sure, that's a good idea. I've added some basic HTML and an ampersand to the labels. Doing that does raise an interesting point: in
\Drupal\config_translation\FormElement\ListElement::getGroupTitlewestrip_tags()the title, which is probably a bit heavy handed. (Summary elements can contain a fair bit of HTML.) Thus, westrip_tags()the expected value in the test.But that's a different issue for a different day...
From #42:
Except that these are no longer
fieldsetbutdetailselements. Regardless, I've updated the wording -- let me know if that clarifies things.Comment #45
gábor hojtsyThanks!
Comment #46
alexpottCommitted 891e57e and pushed to 8.0.x, 8.1.x and 8.2.x. Thanks!
Comment #50
gábor hojtsySuperb, thanks!
Comment #51
gábor hojtsyWould be a string change in 8.0.6 then I guess.