Problem/Motivation
LanguageSelectWidget
hardcodes the list of languages to LanguageInterface::STATE_ALL
. While that's a reasonable default it should be possible to configure it to use LanguageInterface::STATE_CONFIGURABLE
(i.e. without Not specified and Not applicable).
Proposed resolution
Add a include_locked
setting for LanguageSelectWidget
with a corresponding checkbox in the settings form. We should probably make the label a bit more explicit, such as:
Include locked languages such as Not specified and Not applicable
Depending on that setting either use LanguageInterface::STATE_CONFIGURABLE
or LanguageInterface::STATE_ALL
as the #languages
.
Remaining tasks
User interface changes
None.
API changes
None.
Data model changes
An additional setting for form displays using the language widget.
Comment | File | Size | Author |
---|---|---|---|
#52 | 2827784-46-8.3.4.patch | 6.86 KB | TVoesenek |
#46 | interdiff-41-46.txt | 2.6 KB | maxocub |
#46 | 2827784-46.patch | 6.88 KB | maxocub |
#41 | interdiff-39-41.txt | 2.86 KB | maxocub |
#41 | 2827784-41.patch | 7.19 KB | maxocub |
Comments
Comment #2
tstoecklerMarking Novice. If you want to tackle this and need help please just ask here and I will provide detailed instructions.
Comment #3
tstoecklerComment #4
cebasqueira CreditAttribution: cebasqueira at CI&T commentedComment #5
cebasqueira CreditAttribution: cebasqueira at CI&T commentedHi @tstoeckler
Please send me more information about the settings form that was cited on proposed resolution
Comment #6
tstoecklerSure.
In
LanguageSelectWidget
, you should add adefaultSettings()
which provides an array withinclude_locked
as key and the default value (I guess it should beTRUE
in this case) as the value.Then you should add a
settingsForm()
method which returns a form to configure this setting, so it should just contain a singleinclude_locked
setting which is just a checkbox.Then in
formElement()
you should replace the value of the#languages
key with$this->getSetting('include_locked')
.Does that help?
Comment #7
juancasantito CreditAttribution: juancasantito at MTech, LLC commentedI think this could be a good start for this.
Comment #8
juancasantito CreditAttribution: juancasantito at MTech, LLC commentedComment #10
cebasqueira CreditAttribution: cebasqueira at CI&T commentedComment #11
cebasqueira CreditAttribution: cebasqueira at CI&T commentedComment #12
tstoecklerThanks @cebasqueira for the patch! Thanks also @juancasantito, your patch was almost identical, but had some identation problems, and since this was assigned to @cebasqueira I'm reviewing the last patch. It's best to always keep a watch on if an issue is already assigned to someone else or not.
I think we should wrap the "Not specified" and "Not applicable" in < em > tags.
Other than that, the patch looks great.
This will need some tests and an upgrade path for existing form displays, however. Removing the Novice tag for that, but do feel free to tackle that if you want. I will try to help.
Comment #13
cebasqueira CreditAttribution: cebasqueira at CI&T commentedThe new patch with "
<em></em>
"!Comment #14
tstoecklerThat looks great, thanks! Now just needs tests and an upgrade path, as noted above.
By the way @cebasqueira, it is a best practice to always create an interdiff when you update a patch. That would be great to do, next time (no need to do it for this one, that's fine). More information on: https://www.drupal.org/documentation/git/interdiff
Comment #15
faline CreditAttribution: faline at CI&T commentedHi @tstoeckler, I will try to develop the test for this.
Could you help me with some directions?
Thank you
Comment #16
tstoeckler@faline Unfortunately there are no tests at all for
LanguageSelectWidget
at the moment, so you would have to create a new test. Maybe you can look atOptionsWidgetsTest
for inspiration. Basically we would need 2 test methods, one which just uses the default settings and asserts that the locked languages are there and then another test method which disables theinclude_locked
setting and then asserts that the locked languages are not there.Also putting this on the D8MI sprint board, as this is actively being worked on ATM.
Comment #17
faline CreditAttribution: faline at CI&T commented@tstoeckler I'm trying to create the Test but when I try to run it, I receive the error on log:
But I cannot figure out what is happen.
Comment #18
faline CreditAttribution: faline at CI&T commentedThe attached patch is just to help to find the problem with the test class
Comment #19
Wim LeersYour classname doesn't match the filename. Hence the error output you see in #17 :)
Comment #20
faline CreditAttribution: faline at CI&T commented@Wim Leers I missed this! My bad! Thank you
Comment #21
faline CreditAttribution: faline at CI&T commented@tstoeckler I'm facing some problems with Drupal installation (I've already create some environments, but none works) for run some tests (included this one).
So I'm unassigned this issue so anyone else could work on it. I will continues try to run this test. If this works I will upload the correct patch.
Thank for your help and @Wim Leers.
Comment #22
faline CreditAttribution: faline at CI&T commented@tstoeckler I'm uploading what I did for test as we talked.
I hope this is on the right path.
Comment #23
tstoecklerLet's see what the bot thinks. Patch looks pretty good.
Comment #29
tstoecklerComment #30
tstoecklerNice work. Please don't be discouraged that I marked a big portion of the test below, the test is actually not that far from what we want, it just needs some tweaks that make a lot of lines of code.
Some ideas for improvement for the test:
FieldTestBase
is an oldWebTestBase
-based test. There is now a new replacement, calledFieldKernelTestBase
. It's very easy to miss, because there are so many different classes at so many different locations... :-/Looking at
FieldKernelTestBase
I'm not sure if we actually need it here, or we can just extendKernelTestBase
directly. Then you would have to do, for examplein
setUp()
but maybe not much more.Either way, the test will then be in the
Drupal\Tests\language\Kernel
and it will be located incore/modules/language/tests/src/Kernel
Again, sorry that this is so weird...
Here, and elsewhere: It's not required, but it's nice to use the short array syntax ([]) for new classes.
This is currently failing, I think, because you are not logged in as an administrator. Instead of creating it from the UI, though, we can create a language directly from code.
Something like this (untested):
So if we use the
entity_test
entity type we can directly use thelanguage
base field that that provides and don't have to add any fields ourselves. We simply have to configure the form display to use the widget with a particular setting.Adapting this from similar code in
OptionsWidgetsTest
you could try something like the following (untested):(That's without the setting. And then you would have to add the setting in the other test method.)
Again, this should not be needed, because we can just re-use the existing
langcode
field.This is not necessarily wrong, but I wonder if we could just go to the add form and do the assertions there? That should work just the same, I think?
I think we don't actually want to assert that the option is selected (or not), but that it exists (or not) so I think we should be using
$this->assertOption()
and$this->assertNoOption()
Hopefully that will allow you or someone else to move this along. Also re-marking "Novice" as - now that you've put the test in place, I think it's a Novice task to fix at least some of the issues I noted above, even if some might be a bit trickier.
Comment #31
tstoecklerComment #32
faline CreditAttribution: faline at CI&T commented@tstoeckler thank you for point out what should change on test code!
As soon as I have time I will try to do these changes. If someone else do it first, that is no problem either.
Thanks! :)
Comment #34
maxocub CreditAttribution: maxocub commentedHere's a new version of the test using KernelTestBase.
Comment #35
maxocub CreditAttribution: maxocub commentedBack to Needs work to add an upgrade path.
Comment #36
maxocub CreditAttribution: maxocub commentedI'm not sure this is the best way to do the upgrade path, but that's what I've got for now.
Comment #38
maxocub CreditAttribution: maxocub commentedComment #39
maxocub CreditAttribution: maxocub commentedHere's a test for the update path.
Comment #41
maxocub CreditAttribution: maxocub commentedChanged the hook_update_N() to a hook_post_update_NAME(), as suggested by @tstoeckler on IRC.
Comment #43
maxocub CreditAttribution: maxocub commentedCI error, back to NR.
Comment #44
tstoecklerAwesome, thank you so much. Looks absolutely perfect.
Comment #45
alexpottThis looks a bit odd - might we save a entity display twice?
How about we do something like:
There's no chance that settings will have any thing in?
This test is prone to failure :( we can't be sure that an assert is made. Because of all the foreaches and if... Just load a specific entity form display and check before and after.
Comment #46
maxocub CreditAttribution: maxocub commentedMade the changes from #45.
Comment #47
tstoecklerPerfect, thanks for the review @alexpott and the quick turnaround @maxocub!
Comment #48
alexpottCommitted b67ccdc and pushed to 8.4.x. Thanks!
Comment #50
Gábor HojtsyThanks all, this looks great :)
Comment #52
TVoesenek CreditAttribution: TVoesenek commentedI've made a version of the patch from #46 for 8.3.x, so it can be used there too.
Comment #53
maxocub CreditAttribution: maxocub as a volunteer and commented