Problem/Motivation

Running drush content-first:export --entity=menu --language=en exports menus in all site languages instead of only the requested one.

There are two bugs in ContentFirstCommands::export():

  1. The $languages variable is parsed after exportMenus() is called, so it is never available for menu exports.
  2. exportMenus() does not accept a language filter parameter at all — it always iterates over every language returned by LanguageManagerInterface::getLanguages().

The @option language docblock also incorrectly documents the option as "nodes only", which is misleading.

Steps to reproduce

  1. Install the module on a multilingual site (e.g. English + Spanish).
  2. Run drush content-first:export --entity=menu --language=en.
  3. Observe that files for all languages (e.g. menu-en-main.md and menu-es-main.md) are exported instead of only menu-en-main.md.

Proposed resolution

  1. Move the $languages parsing block above the exportMenus() call in export().
  2. Pass $languages as a new parameter to exportMenus().
  3. Inside exportMenus(), skip any language not present in the requested list when the list is non-empty.
  4. Update the @option language docblock to remove the "(nodes only)" restriction.

Relevant changes to src/Commands/ContentFirstCommands.php:

// Move language parsing before exportMenus() call. $languages = !empty($options['language']) ? array_map('trim', explode(',', $options['language'])) : []; if ($exportMenus) { $this->exportMenus($folder, $bundles, $status, $rewriteLinks, $languages); } 
protected function exportMenus( string $folder, array $bundles, ?int $status = NULL, bool $rewriteLinks = FALSE, array $languages = [], ): void { // ... $allLanguages = $this->languageManager->getLanguages(); foreach ($allLanguages as $langcode => $language) { if (!empty($languages) && !in_array($langcode, $languages, TRUE)) { continue; } // export logic } } 

Remaining tasks

  • Review and merge the patch.
  • Add a unit test for ContentFirstCommands covering the language filter for menus.

API changes

ContentFirstCommands::exportMenus() gains a new optional parameter array $languages = []. Existing callers passing positional arguments are unaffected since it is appended with a default value.

Command icon 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

gedur created an issue. See original summary.

  • gedur committed 5f251f6c on 2.x
    Issue #3589813: Fix --language option not filtering menu exports in...
gedur’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.