You are here

protected function MenuExportConfigurationForm::backupMenus in Menu Import and Export 8

1 call to MenuExportConfigurationForm::backupMenus()
MenuExportConfigurationForm::submitForm in src/Form/MenuExportConfigurationForm.php
Form submission handler.

File

src/Form/MenuExportConfigurationForm.php, line 79

Class

MenuExportConfigurationForm
Configure Menu Export settings.

Namespace

Drupal\menu_export\Form

Code

protected function backupMenus($menus) {
  $config = $this
    ->config('menu_export.export_data');
  $config
    ->delete()
    ->save();
  if (empty($menus)) {
    return false;
  }
  foreach ($menus as $menu) {
    $menuLinkIds = \Drupal::entityQuery('menu_link_content')
      ->condition('menu_name', $menu)
      ->execute();
    $menuLinks = MenuLinkContent::loadMultiple($menuLinkIds);
    $saveMenu[] = '';
    foreach ($menuLinks as $link) {
      if (!empty($link)) {
        $linkArray = $link
          ->toArray();
        unset($linkArray['id']);
        foreach ($linkArray as $key => $linkArrayItem) {
          $linkData[$key] = reset($linkArrayItem);
        }
        $saveMenu[$link
          ->uuid()] = serialize($linkData);

        //$data[$link->id()] = $linkData;
        unset($linkData);
      }
    }
    $config
      ->set($menu, $saveMenu);
    unset($saveMenu);
  }
  $config
    ->save();
  return true;
}