Problem/Motivation

Using drush 11 and drupal 9.3.16. import(force) the Administration menu items are not enabled.

Steps to reproduce

  1. export the Administration menu
  2. import(force) the Administration menu

Proposed resolution

When I exported the structure_sync.data.yml file I found that the enable and expanded field value are true or false

    enabled: true
    expanded: false

But in the MenuLinksController.php, the logic is:

        'expanded' => $menuLink['expanded'] === '1' ? TRUE : FALSE,
        'enabled' => $menuLink['enabled'] === '1' ? TRUE : FALSE,

So the enabled and expanded will be FALSE forever.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#4 3285551-4.patch2.74 KBnarendra.rajwar27
#2 3285551-1.patch5.48 KBzhangjy
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

zhangjy created an issue. See original summary.

zhangjy’s picture

StatusFileSize
new5.48 KB
louis-cuny’s picture

Status: Active » Needs work

1. We can remove the stupid "? TRUE : FALSE".
2. We should check previous versions where "1" was used and try both solutions: in_array($menuLink['expanded'], ['1', TRUE], TRUE)

narendra.rajwar27’s picture

Status: Needs work » Needs review
StatusFileSize
new2.74 KB

Updating patch as suggested in comment #3
Since the patch in comment #2 is not getting applied, so could not create Inter-diff file.

Status: Needs review » Needs work

The last submitted patch, 4: 3285551-4.patch, failed testing. View results

louis-cuny’s picture

Status: Needs work » Needs review
chrisck’s picture

Tested path #4 and it is working. Administration menu items are enabled on import.

xamount’s picture

Title: cannot import menu correctly » Importing menus items are always disabled
Priority: Normal » Critical
Status: Needs review » Reviewed & tested by the community

The patch at #4 also solved the issue for me.

In my case, I exported menus locally as I usually would, but when I deployed and imported using drush im (full), the menus items exist, but they are always disabled. With the patch, it now works as expected (menu items exists and are enabled if they were set so).

Setting the priority to "Critical" as the drush im is basically broken without this patch.

For those interested in correctly exporting menus locally and then importing on production, here are the steps:

  1. On local, add/delete your menus.
  2. drush em
  3. drush cex
  4. git commit all changed files
  5. On production: drush cim, then drush im

In typical deployments, drush updb is usually run first, so you can write a hook_update like this:

/**
 * Run drush im.
 */
use Drush\Drush;
function YOURCUSTOMMODULE_update_9007(&$sandbox) {
  /** @var \Consolidation\SiteAlias\SiteAliasManager $alias_manager */
  $alias_manager = Drush::service('site.alias.manager');
  $selfRecord = $alias_manager->getSelf();
  $options = ['choice' => 'full'];
  Drush::processManager()->drush($selfRecord, 'cim', [])->mustRun();
  Drush::processManager()->drush($selfRecord, 'im', [], $options)->mustRun();
}

This will import your config first, then import your menus. So then you do not need to manually run drush im on production.

Basically you need to run drush cim first because it will import the structure_sync config. Only then you can run drush im.

(Change 9007 to match your hook_update numbering)

louis-cuny’s picture

  • louis-cuny committed 8755c93 on 2.x
    Issue #3285551: Importing menus items are always disabled
    
louis-cuny’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the reviews !

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.