In Drupal 7, install profiles could implement the pseudo-hook hook_profile_details() to pre-select a language for the person installing Drupal. They could also allow the person installing to select a language, but use hook_install_tasks_alter() to modify the default core UI for doing so.
As a result of #1260716: Improve language onboarding user experience, this is no longer possible in Drupal 8. As discussed in that issue, this is the (major-priority) followup task for adding that back in some way.
There was some proposed code for keeping that feature in place in the above issue and elsewhere (see for example http://drupal.org/files/distro-settings.patch). That did not go in, primarily due to the feedback that it was too odd for the behavior of a hook to be influenced by a property in the profile's .info file.... So, we need to come up with a cleaner way of doing it. Perhaps a second hook instead, which determines the installation steps that are allowed to be altered by hook_install_tasks_alter()? And ideally, the only things that ever get passed in to hook_install_tasks_alter() should be the tasks that actually are able to be altered for real.
Comment | File | Size | Author |
---|---|---|---|
#31 | 1386394-31.patch | 15.62 KB | tstoeckler |
Comments
Comment #1
David_Rothstein CreditAttribution: David_Rothstein commentedMarking this postponed on #1351352: Distribution installation profiles are no longer able to override the early installer screens for the time being, because that's another (potentially cleaner) way to add back this feature, or at least a close-enough equivalent of it. However, it's also a much bigger issue. So we'll see how it goes for a little while before continuing here.
Comment #2
David_Rothstein CreditAttribution: David_Rothstein commentedI think it's time to reopen this.
Due to #1337554: Develop and use separate branding for the installer, this becomes a bit more important since the word "Drupal" now appears in large letters on the language selection page of the installer, and distros might reasonably want their own name to appear instead.
Also, in the interim, we now have the concept of "exclusive" install profiles (which is a feature that's specifically targeted for Drupal distributions). If an "exclusive" install profile is being used, we already skip the profile selection page and choose one automatically. So we can just reuse that code here rather than adding a new .info file property, and it becomes very simple.
Comment #3
David_Rothstein CreditAttribution: David_Rothstein commentedHere's a patch.
I'm not a big fan of the change to install_load_profile() in the attached patch (especially in light of #1338384: install_profile_info() returns inconsisent data; without fixing that bug at the same time this is likely to cause problems, and maybe in the case of command-line installs it would cause problems either way).
But otherwise it seems pretty straightforward.
The second attached patch (the "helper" patch) can be used for manual testing - it modifies the Standard install profile to simulate a Drupal distribution. You can see that before applying the main patch, the distribution's name will not appear on the language selection screen (only on the screens after that), and the modifications which the distro attempts to make to the language screen don't take effect either. With the main patch applied, all modifications work as expected.
There is still no magic way for an install profile to preselect a language (as in Drupal 7), but I think that's acceptable because you can achieve the same thing relatively simply by having an entirely custom language selection callback in hook_install_tasks_alter() and having the callback function do something like this:
Comment #4
David_Rothstein CreditAttribution: David_Rothstein commentedOops, let's try again - apparently patches need "do-not-test" rather than "DO-NOT-TEST" in order to make the testbot skip them.
Comment #5
YesCT CreditAttribution: YesCT commented#1351352: Distribution installation profiles are no longer able to override the early installer screens is still really important.
Comment #6
sunThis should be resolved through the new architecture provided by #1351352: Distribution installation profiles are no longer able to override the early installer screens
Thus, postponing on that.
Comment #7
penyaskitoPostponing issues were fixed.
Comment #8
YesCT CreditAttribution: YesCT commentedI was looking at https://www.drupal.org/core/d8-allowed-changes#evaluate
while working on major triage
but I dont know what a new solution would look like here. so I dont know how to evaluate it for rc or being postponed.
Comment #9
Kristen PolI'm trying to look at this at the BADCamp sprint.
Comment #10
Kristen PolAfter battling updating php on my old computer, I have made some progress on this. Here are my notes:
install_begin_request
after the profile is read in:This feels like a good approach to me but, before I put together a patch, I would like thoughts on this.
I haven't yet changed the list of langcodes in the installer form but I imagine this is doable in
hook_form_install_configure_form_alter
. I'll play with that next.Comment #11
Kristen PolI'm looking at note 2 in my comment #10, perhaps I didn't understand the comments and it can't be passed in via command-line (unless it's "in the URL"). The comments that made me think that was an option were:
in
install_state_defaults
.Comment #12
Kristen Pol@YesCT looked at #10 and #11 and thought that all is ok to go forward with a patch based on the 3 and 4 notes from #10. Would love some other feedback as well.
As for modifying the langcode form field in the installer, this should be easy to do in
hook_form_install_configure_form_alter
but it's not working. I tried in the multilingual_demo installer as well as the openchurch. For both of these, the form alter hook doesn't appear to be firing. But, I don't have PhpStorm running properly on my old computer and just doing print_r... I did try putting indie();
and this didn't kill the install so something is whacky.Comment #13
Kristen PolOk, I was being dense before and was trying to update the
hook_form_install_configure_form_alter
function which is the last form on the screen.This works fine:
So, updating the existing list of languages is easy peasy.
Comment #14
Kristen PolI have a patch for supporting adding langcode to the distribution's
.info.yml
file like:To test it, download a distribution like Open Church and update the .info.yml to add this text. Then run through the installer and it should choose the language you specified by default and then bypass that part of the install (skips to the second step).
Comment #15
Kristen PolActually, #14 has an error... adding a new patch in a bit.
Comment #16
Kristen PolOk, here's a new patch.
Comment #17
Kristen PolComment #19
Kristen PolThe things that need to be tested:
.info.yml
file.info.yml
file.info.yml
file.info.yml
file.info.yml
file.info.yml
fileComment #20
Gábor HojtsyIs it possible to do automated tests for this? It seems to me like it is.
Comment #21
tstoecklerYay, this makes a whole lot of sense. I like this a lot.
I will see if I can allocate some time to write some tests.
One (minor) note on the patch:
I find the logic here to be a little bit unintuitive. Especially because the comment
comes before a condition which does not check whether anything changed. I understand that it effectively does because of the previous condition, but I still think it's confusing (at least to me). Also I think not always setting$install_state['parameters']['langcode']
is an unnecessary optimization. I would propose something like the following for this part:EDIT: Fix code formatting
Comment #22
Kristen PolThanks for the feedback @tstoeckler! I also felt it was not as elegant as I'd like but your suggestion:
would mean that the if statement won't fire, right? Because before it the
$install_state['parameters']['langcode']
is set to$default_langcode
and then it's checking if it's not equal.What I would prefer would be to move the entire code block:
to below this new code and then we can yank out the part that is doing the
setDefaultLangcode
and it will simplify things. But, I'm not clear if that will mess anything up. Perhaps I should just try it. :)Comment #23
tstoeckler1. yes, you are right. I am stupid
2. that sounds like a *great* idea!
Comment #24
Kristen PolIt seems to work great for me. I removed the first setDefaultLangcode logic and moved it after the profiles are pulled in this is the code:
Thoughts? Should I make a patch with this instead? Anyone think of a reason why that setDefaultLangcode logic needs to before the profiles are read in?
Comment #25
Kristen Pol#23 You are not stupid. :) See #24. Would love your input on the logic move.
Comment #26
Kristen Pol@tstoeckler gave the thumbs up so here's a new patch. He's hoping to write tests tomorrow.
Comment #27
tstoecklerYeah, I looked at the surrounding code and nothing even remotely language-related is happening between those two spots in the code, so it's totally harmless to move the hunk a little bit down. Will write some tests later, hopefully.
Comment #28
tstoecklerHere we go.
Not quite sure whether this passes, because I had some filesystem problems locally, but at least in terms of coverage this should be sufficient. I've added 3 tests extending
InstallerTestBase
for cases 2.-4. described in #19. (Thanks for that, by the way, that was incredibly useful!) 1. is already covered byInstallerTranslationTest
.Comment #29
Kristen PolHurray! Thanks for writing these. :)
Minor things:
Needs doc block?
Minor nitpick: Move some of "The unrouted..." to the previous line?
Needs doc block?
For the last test, shouldn't the langcode passed in the URL be something other than 'de'? That way we know it was overridden with the yml file value. Or, maybe I'm not reading it right?
Comment #30
tstoeckler1.+3. will fix
2. There are two distinct points being made here, so I went with the explicit line break. No biggie though, if you think it should wrap nonetheless.
All the different tests are a bit confusing, so please do make sure that I'm not mistaken, but I think what you're referring to is #19.4 which is covered by
DistributionProfileTranslationQueryTest
.Just noticed the following, as well:
Boo! (Copy-paste much?)
Comment #31
tstoecklerHere we go.
Comment #32
YesCT CreditAttribution: YesCT commentedI'm going to review this now. [edit: and then had to stop. will come back to this later, if no-one beats me too it. but just wanted to make sure it was clear for other reviewers also.]
Comment #33
Gábor HojtsyLooks good for me. Thanks for the reviews folks :) Moving to 8.1.x for inclusion.
Comment #34
catchCommitted/pushed to 8.1.x, thanks!
Comment #36
Gábor HojtsyYay, thanks!
Comment #38
xjmComment #39
xjmThis issue is missing a change record. (We should add change records for noteworthy API additions.)
Comment #40
Gábor HojtsyPublished https://www.drupal.org/node/2709451.