Problem/Motivation
Part of #3582246: [meta] CLI in Core community initiative. Referenced from theCLI in Core Initiative spreadsheet.
Similar to being able to apply a recipe, Drupal should provide a command to install a module or a theme from the CLI.
Steps to reproduce
Working on a Drupal Core CLI Command issue > Test Commands
For step 7, Do any additional setup instructions for the command, try installing an optional core module that depends on another optional core module such as rest module or workspaces_ui module. Confirm the module is usable in the UI.
Proposed resolution
An extension install command exists to install a comma-separated list of modules or themes. The command should not attempt to install if requirements are not met. It’s standard output should contain a success message and module configuration links similar to installing a module from the module list page.
The installation methods for modules and themes are changed to separate getting extensions to install and installing them.
Remaining tasks
- Determine which CR to add this to
Follow up:
#3613834: Install translations after installing a module/theme via CLI
User interface changes
No
Introduced terminology
No
API changes
The module and theme installer class install methods work slightly differently, and an extra method is needed to get the extensions to install.
Data model changes
No
Release notes snippet
To be determined
| Comment | File | Size | Author |
|---|
Issue fork drupal-3594334
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
mradcliffeAdded link to #2894476: [PP-1] Provide commands which are helpful for core development that was the original feature request, but no work was done on installing extensions in that issue.
Comment #3
nicxvan commentedComment #4
moshe weitzman commentedThe drush pm:install command provides a nice interaction model where it automatically enables the module(s) unless there are dependent modules also need updating and were not mentioned. It also checks various requirements before the install starts. I think these are nice and ideally will stay when this command ports to core. In order to achieve this, the ModuleInstaller will need refactoring.
Also, we may or may not want to bundle theme and module install into one command. Drush has them separate but thats a historical artifact not a design decision.
Help wanted.
Comment #5
nicxvan commentedI'm not opposed to some refactoring to make this more resilient.
I would like to get the command and ui install process closer rather than further apart unless there is a strong reason the cli should act differently.
Comment #6
berdirAlso, module installer needs the ability to process batch operations, for example for locale translation import. We could in theory get in a first iteration without that, but it would result in different behavior between CLI and UI. That UI helper method would need to be split from the form state to work for CLI as well.
The core logic for install requirements and dependencies is in \Drupal\system\Form\ModulesListForm::buildModuleList/submitForm, There's also a special case for non-stable module confirmation in the UI.
Comment #7
xmacinfoI think the command-line should only enable a module and not to try to pipe in additional tasks, like importing translations.
So we could do something like enable a few modules and after that import the translations separately.
Comment #9
moshe weitzman commentedI pushed an MR for this.
The MR as it stands is targeted to Drupal 12. Once that gets in, someone can work on an 11.5 version IMO. This is chosen in order to allow refactoring of dependency checking, which unlocks the strong validation/user-promptingDrush emits clickable links at end of module install with links to help, permissions, and config pages. This is left as a followup, partly because of the difference between modules and themes.AI-Generated: Code - Yes ... All issue and MR comments are fully authored by me, because that is respectful of the reviewers and shows to myself and others that I understand what I am contributing. This disclosure also appears in the MR description.
Comment #10
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #11
moshe weitzman commentedBack to NR
Comment #12
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #13
moshe weitzman commentedAs for interactively prompting the user to pick a module/theme to install, I opened #3606645: Add Laravel Prompts as a dependency for CLI app and affiliated it with the meta.
Comment #14
moshe weitzman commentedThe NR bot is apparently not using the same PHPCS that Gitlab CU uses so the PHP 8.5 pipe operator confuses it
Comment #15
ressaThanks @moshe weitzman, the new
drcommand works well, and the only thing I have encountered so far trying out theinstallcommand is that only a comma-separated list of modules is supported, where Drush also supports a space separated list.These two (space, or comma+space) fail with the same error message:
This one (only comma) succeeds:
The
drush installcommand supports multiple modules, either space or comma separatedIt would be great if
dr installalso supported installing multiple space separated modules, if possible?Comment #16
moshe weitzman commentedI deliberately did not support space separated arguments (also called a variadic argument), even though Drush does support that. The issue with them is that you can never add another argument after that. Forever more you have to assume that any argument to the command is an extension name. Thats not the end of the world. Yet in Drush a few times I wished I didn't have that limitation. I can make this change if folks think its important.
Comment #17
moshe weitzman commentedHow can I coax the Needs Review Bot to ignore this issue? Its vandalizing the Status field.
Comment #18
nicxvan commentedAdd this tag to skip the bot.
Comment #19
ressaThanks for a fast reply and explanation about the comma-separated argument values, I had a hunch that it was probably deliberate, but wanted to check. I do understand that there are downsides to supporting space-separated modules ... it's complicated to discern between values and arguments.
We could keep it like it is (comma-separated), but possibly either 1. Improve the error message, making it clearer that only a single comma will work as separator, or 2. Add an example string like
ex:install basic_auth,serializationin the output ofdr ex:install -h? Because some might try comma+space, which works in Drush. If not, it's fine, people will realize the new syntax over time :)Comment #20
moshe weitzman commentedI opted to add a couple usage example. However that exposed a bug in our handling of invokable commands. I submitted a fix at #3606744: Invokable commands dont show their usages in help
Comment #21
ressaThe improved "Usage" example looks great, and the added
ex:install views,views_uiwill work well to inform the users of the correct syntax, thanks!Comment #22
xmacinfoWhy so many aliases for the same set of commands?
pm:installvsex:installAs I can see,
pmandexare doing the same thing.Comment #23
moshe weitzman commentedWe actually dropped one in the MR. pm:install has 6 aliases. ex:install has 5. Unlike Drush Help, Console Help shows Usages and Aliases mixed together.
Comment #24
ressaThinking more about this, I am not a fan of the
ex:installand itsexinalias.And while I understand the desire to use
installfor installing Drupal, I think it is better used for installing modules and themes, since that command is used much more often, in daily Drupal development.Can we instead use
install-drupalfor installing Drupal?... because then, while we are changing things, we can clean up the command for installing modules, to just be either
installor its aliasin, getting rid of old cruft, such aspm:installandenable(which is misleading) and mainly there for historical reasons:Comment #25
nicxvan commented@ressa I'm not opposed to this discussion, but installing a module is what happens when you run composer require or install commands.
Enabling is what this command does.
Install is also what happens with what you are proposing become install-drupal.
The aliases are really just for muscle memory, I don't think it's really craft to keep them.
Comment #26
ressaThanks for weighing in @nicxvan. But actually, the difference between these concepts is something many new users mix up, I have seen it often in the Drupal forum. I left this comment April 2024 to clear it up:
From https://www.drupal.org/forum/support/installing-drupal/2024-04-26/need-c...
... and to add, we delete a module/theme's code base with
composer removeand uninstall with Drush or GUI. Important note: when you uninstall a module, all configuration gets deleted. In Drupal 7 it was kept, which is whyenable/disablewere correct terms for Drupal 7, but not for Drupal 11.Comment #27
nicxvan commentedYeah the services are called moduleInstaller and themeInstaller too.
Comment #28
xmacinfoPersonally, I would keep the 'install' lingo only for "composer install" when a Composer lock file exists..
For modules/themes, the instlallation is a two-step process :
1. Download (composer based)
2. Enable (UI or CR based)
So I prefer to keep
enable:and get rid of
cr install.Edit: I hope that in the future D13, we will be able to enable/disable a module like we did in Drupal up to 7. Or provide a way to export the directly related configuration (not the dependency tree) of a module when we uninstall a module. But this is another story.
Comment #29
ressaIt's unfortunate that Composer is using "install" as well ...
But the Drupal User Guide strictly module page uses install, and it is a conscious choice, see #2891294: [Meta] Use Install/Uninstall consistently for turning modules/themes on/off (not Enable) and also Installing Modules.
Because if we use enable, we should also use disable for uninstalling a module. But that's not the only thing that happens, all the configuration is removed.
Comment #30
moshe weitzman commentedComment #31
mradcliffeI made attempt to update the issue summary with the current proposed resolution in the merge request along with testing instructions linking to our initiative docs.
Comment #32
mradcliffeI tried manually testing this using a composer project setup installing workspaces_ui and rest. I ran into an issue where when visiting the site I got a WSOD when I tried to visit the admin page until I rebuilt cache.
ddev exec dr ex:install workspaces_ui,restException:
Stack trace:
Comment #33
mradcliffeThis also happened when I tried a simple checkout using quick-start (SQLite).
I did not run into the same issue installing the same modules from the user interface.
Comment #34
moshe weitzman commentedThanks for finding that. Now fixed. The fix was to flip that $allow_dumping DrupalKernel param that we discussed in the original issue. That necessitated a consolidating duplicate applicationTester() methods used in 2 test classes. $allow_dumping now defaults to TRUE like Drush has done for years. This fixes quick-start as well.
The CI warning is unrelated to this PR, and is happening on other pipelines.
Comment #35
nicxvan commentedThis seems related #3611084: DrupalApplication should use the compiled container
Comment #36
moshe weitzman commentedOh wow. That issue contains an identical fix. I guess we should mark this one as Postponed on that. I'll leave the fix here too until that one gets in.
Comment #37
moshe weitzman commentedThe dependant issue was merged, so I removed my commit and pulled changes from main.
Back to NR. Again, the CI warning is unrelated.
Comment #38
nicxvan commentedI was able to do some manual testing.
I installed a module by itself
I called two modules, one already installed
I installed a theme
I installed a module with dependencies
I installed and already installed module
I installed a theme with dependencies
I installed a module and theme at the same time (gave appropriate error)
Do we need a confirmation for experimental modules and themes?
I have to still go through the code flow in detail again.
Comment #39
moshe weitzman commentedWe have never had that for Drush, and it never got any pushback. I suggest that be proposed in a new issue by anyone who feels strongly for it.
Anyone up for an RTBC?
Comment #40
nicxvan commentedI think the experimental module confirmation can be a follow up.
If someone rtbcs before I have a chance to review again I'd like confirmation they tested the ui install process too for modules and themes.
I didn't do that on this branch yet and we are changing that code as well.
Comment #41
nicxvan commentedOk I tested the scenarios that made sense in the UI:
I installed a module by itself - Works
I called two modules, one already installed- N/AI installed a theme - Works
I installed a module with dependencies - Works
I installed and already installed module- N/AI installed a theme with dependencies - Works
I installed a module and theme at the same time- N/AI also checked the following items in the UI and CLI
Experimental themes, Experimental modules.
Both worked as expected, no confirmation prompt on the CLI, but that is fine as mentioned in 39 I think.
Comment #42
nicxvan commentedGot a question on some of the changes in the ModuleConfirmForm, I'm not sure how many of those changes are necessary in general.
Other than that I did a lot of manual testing including config import.
We need to figure out where the CR will go, if there is a new one for 11.5 already for CLI commands.
Also we need the follow up for the batch processing for translations.
Comment #43
moshe weitzman commentedI have no pref. A new one for 11.5 sounds good. Do we usually do a CR for new features? Seems more like a release highlight than a change.
I have created #3613834: Install translations after installing a module/theme via CLI.
Comment #44
mradcliffeUpdating the parent to track underneath "stable" meta instead. I kept the component for this issue for now.
Comment #45
nicxvan commentedI think this is ready now!
It's a little bit bigger than I'd like, maybe we could have split the module and theme install into two issues, but this helps make sure the refactoring is consistent across the two.
I provided a couple of suggestion that were applied to the ModuleConfirmForm to streamline the changes a bit.
There is a follow up for translations here: #3613834: Install translations after installing a module/theme via CLI
And we still need to figure out which CR it goes in, I added a remaining task for both.
Comment #46
nicxvan commentedComment #47
ressa... and
pm:installshould probably also be let go, since thepm:prefix is no longer used. In fact allpm:-prefixed aliases should go, but that's probably for other issue(s).Letting go of the four old aliases would result in short and precise documentation.
Command help
General help would be much more readable
Currently, it starts with a long list of aliases, pushing the actual documentation text far to the right:
Comment #48
catchDo we need a separate issue to look into support for deprecated aliases - e.g. we don't list them in the UI, they work, you get an annoying message that they're going to go away etc?
Comment #49
ressaThat's a great idea @catch, and I created an issue.
About this
installcommand, @mradcliffe commented:That sounds great, could that be handled in the issue I just created, or perhaps needs a new issue?
Comment #50
nicxvan commentedYes, let's handle this in the issue you created, it's worth it's own discussion and we can pivot after.
I think getting some of these commands in first is far more important.
Comment #51
ressaThanks for fast feedback, let's keep this issue moving.
Comment #52
catchIt's not clear to me why we're not adding the new methods to the interfaces. This is allowed in minor versions where there's a 1-1 relationship between the interface and the class per https://www.drupal.org/about/core/policies/core-change-policies/bc-polic...
Comment #53
nicxvan commentedI think I was trying to avoid the disruption, but even though I felt strongly about it before I'm struggling to justify it now again.
If it's just a matter of adding the interface docs and method then I think we should do it, sorry @moshe.