Problem/Motivation
SystemAdminThemePreprocess::preprocessSystemModulesDetails() uses the following code.
// Identify modules that are depended on by themes.
// Added here instead of ModuleHandler to avoid recursion.
$themes = $this->themeExtensionList->getList();
foreach ($themes as $theme) {
foreach ($theme->info['dependencies'] as $dependency) {
if (isset($form[$dependency])) {
// Add themes to the module's required by list.
$form[$dependency]['#required_by'][] = $theme->status ? $this->t('@theme', ['@theme (theme)' => $theme->info['name']]) : $this->t('@theme (theme) (<span class="admin-disabled">disabled</span>)', ['@theme' => $theme->info['name']]);
}
}
}
That code would output, in the Required by list and when the theme is enabled, the literal string @theme, not the theme name, because the first argument passed to $this->t() contains only the @theme placeholder, for which the array passed as second argument does not provide any value.
When the theme is disabled, the theme name is correctly shown.
This bug has been introduced in #474684: Allow themes to declare dependencies on modules, for which a new commit has been done in Drupal 9.0.x and Drupal 8.9.x. It is only evident for themes that depends on modules. Drupal core themes do not depend on modules, but some contributed themes could require some modules.
Proposed resolution
Change the quoted code to the following one.
// Identify modules that are depended on by themes.
// Added here instead of ModuleHandler to avoid recursion.
$themes = $this->themeExtensionList->getList();
foreach ($themes as $theme) {
foreach ($theme->info['dependencies'] as $dependency) {
if (isset($form[$dependency])) {
// Add themes to the module's required by list.
$form[$dependency]['#required_by'][] = $theme->status ? $this->t('@theme (theme)', ['@theme' => $theme->info['name']]) : $this->t('@theme (theme) (<span class="admin-disabled">disabled</span>)', ['@theme' => $theme->info['name']]);
}
}
}
Issue fork drupal-3586099
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
avpadernoComment #4
avpadernoComment #5
avpadernoComment #6
avpadernoComment #7
avpadernoI could have used the following code, but I decided it was a minimal optimization.
It should avoid that
'@theme'and'@theme (theme)'are exchanged again, but I do not expect that to happen again.Comment #8
avpadernoThe test failure (ConfigInstallProfileOverrideTest.php, line 141) does not seem caused by this change.
Comment #9
smustgrave commentedCan we update the summary where this was inverted to see if any discussion was had for it.
Comment #10
avpadernoThis is not an intentional change, and it introduces an error. What would be shown as dependency is not the theme name, but the literal string
'@theme'because'@theme'is not one of keys in the array passed as second argument (which in fact is['@theme (theme)' => $theme->info['name']]).The code I quoted is for themes that depend on modules. Drupal core themes do not depend on modules, so this bug is not evident for them, but it will appear when a contributed theme depends on a module (which does not probably happen so often).
Knowing in which issue this change has been done could serve to know if the same change has been done in more files, in the same commit. For that, it is sufficient to use
git grep --fixed-string, which would retrieve similar typos done in other commits too.Comment #11
smustgrave commentedI’ll leave this for others then
Comment #12
avpadernoThe following code has been added in #474684: Allow themes to declare dependencies on modules.
None of the comments in that issue says that passing
'@theme'as first argument and['@theme (theme)' => $theme->info['name']]as second argument was intentional. (It should not be intentional, since that would output @theme as literal string, not the theme name.)Comment #13
avpadernoI made the title and the issue summary more explicit about what the bug is. I also added in the issue summary what I discovered about the issue that added the quoted code.
Comment #14
smustgrave commentedNice find, change looks good to me.