Import/Export menu items

Hi,

I am getting desperate here trying to find a way to do something as simple as exporting and importing menus with their items.

The only exportable thing about a menu out of the box is the menu itself, but not its items, so it’s kind of useless. Apparently there are no modules out there that can do the job in the same way as we used to do it in D7. More info: https://drupal.stackexchange.com/questions/180260/how-do-i-export-my-site-structure

The couple of modules I tried didn’t do the trick, since they were supposed to be used alongside Drush or some other server tricks:
https://www.drupal.org/project/menu_export
https://www.drupal.org/project/structure_sync

There’s a port of the original D7’s menu import that I normally used to do this, but it’s stalled for the moment, and I don’t have time to contribute (although I might do in the future):
https://www.drupal.org/project/menu_import

So the question is: do you Drupal masters know about a way to synchronize menus between sites? Or better still: will we have access to Drush anytime soon? :slight_smile:

Thanks!

we already offer access to drush for test websites. So please try it ( /_site/drush.php )

I will test the other options like Deploy module and menu_export and come back with my feedback afterwards

Cheers,
Eduardo

Hi
to export and import menus. You need to enable the module Menu Export, after that:

  • Go to /admin/config/development/menu_export, select the menu that you need and save it.
  • Go to the tab export (/admin/config/development/menu_export/export) and export the selected menu.
  • Go to /admin/config/development/configuration/single/export select in Configuration type list “Simple Configuration” and select in Configuration name list the items menu “menu_export.export_data”

when you do that in the field “Here is your configuration:” you will get your configuration for your menus them copy it,

In your new site

  • Go to (/admin/config/development/configuration/single/import) in order to import your configuration.
  • select Configuration type “Simple Configuration” and Paste your configuration in a field “Paste your configuration here” , them import it

Play around this steps in order to import your menu. The configuration synchronization is the way to synchronize to sites, your able to export your full site configuration and import in other site or you can select single files.

1 Like

Hi,

thanks for your reply. I forgot to mention that I tried this but it failed. I think the problem is my source and target sites are different (they didn’t diverge from an initial clone), so the menu items UUIDs were different.

In situations like this, which can happen during migrations, or just when we have the original structure in some other site for whatever reason, the UI version of the Menu Export module won’t work.

However, I found a solution!

Here’s the explanation on how to do it with the Structure Sync module: https://www.drupal.org/project/structure_sync/issues/2957187

It involves two steps to export, and two steps to import. Apparently the first step puts some configuration info on the DB, and the second step creates a file from that configuration, so it can be copied over to the target site, and be imported by applying the same steps in inverse order. Summing up:

  1. Drush in source site:
> drush export-all
> drush config-export
  1. Copy the structure_sync.data.yml file to the target site

  2. Drush in target site:

> drush config-import
> drush import-all

In my case I needed to ‘hack’ the exported menu to make the UUID match the target one, so I exported the target menu first to find out this value. It worked like a charm.

Hope this is useful!

Note: the Structure Sync module has to be configured to export just the menu, otherwise lots of other stuff will be exported and imported.

Nice, I am glad that work!! By the way using drush is possible to import only the configuration that you need, for example “drush migrate-import upgrade_d7_user_role”.

I used it to migrate only what I need from my D7 site.

You need also to insert in your settings.php available in your docker site using vi

$databases[‘migrate’][‘default’] = array (
‘database’ => ‘collaboration_7’,
‘username’ => 'User_nasme with admin privilege ',
‘password’ => ‘password’,
‘prefix’ => ‘’,
‘host’ => ‘host.cern.ch’,
‘port’ => ‘3306’,
‘namespace’ => ‘Drupal\Core\Database\Driver\mysql’,
‘driver’ => ‘mysql’,
);
$databases[‘upgrade’][‘default’] = $databases[‘migrate’][‘default’];

ini_set(‘memory_limit’, -1);

check this link to complement this tip https://drupalize.me/blog/201604/custom-drupal-drupal-migrations-migrate-tools

Provably you know about it bat could help to other users in the forum. I am still understanding all the steps of the migration

Best regards,
Raul

1 Like

Just for extra information:

When using the ‘Single import’ option from ‘Configuration synchronization’ (under the admin menu ‘Configuration > Development’) to import a Menu as ‘Configuration type’, you can get this error message:

The configuration cannot be imported because it failed validation for the following reasons:

  • Configuration simple_sitemap.bundle_settings.node.landing_page depends on the simple_sitemap extension that will not be installed after import.

see image:

This can be fixed by installing the ‘Simple XML Sitemap’ module (https://www.drupal.org/project/simple_sitemap).

Just in case someone is fiddling about configuration import/export, this can be useful :+1:

3 Likes

Hello. I created a module that can help syncronizing menu items between envs. It offers both drush and user interface options. Menu migration (Import & Export) | Drupal.org

1 Like