You are here

protected function EntityMenuLinkCloneForm::setUuidForMenuItems in Menu Link Clone 8

Same name and namespace in other branches
  1. 8.3 src/Form/EntityMenuLinkCloneForm.php \Drupal\menu_link_clone\Form\EntityMenuLinkCloneForm::setUuidForMenuItems()
  2. 8.2 src/Form/EntityMenuLinkCloneForm.php \Drupal\menu_link_clone\Form\EntityMenuLinkCloneForm::setUuidForMenuItems()

Set UUID for menu items.

Parameters

object $menu_links_object_multiple: Menu Items Object.

string $target_menu_name: Menu Name for which we need to set UUID.

1 call to EntityMenuLinkCloneForm::setUuidForMenuItems()
EntityMenuLinkCloneForm::cloneMenuLinks in src/Form/EntityMenuLinkCloneForm.php
Clone menu items.

File

src/Form/EntityMenuLinkCloneForm.php, line 162

Class

EntityMenuLinkCloneForm
Provides a menu link clone form.

Namespace

Drupal\menu_link_clone\Form

Code

protected function setUuidForMenuItems($menu_links_object_multiple, $target_menu_name) {
  $uuid_map = [];

  // Create an uuid mapping table.
  foreach ($menu_links_object_multiple as $id => $menu) {
    $uuid = $menu['uuid']['value'];

    // Assume uuid is not duplicated here.
    $new_uuid = $this
      ->genUuid();
    $uuid_map['menu_link_content:' . $uuid] = 'menu_link_content:' . $new_uuid;
    $menu_links_object_multiple[$id]['uuid'] = $new_uuid;
    unset($menu_links_object_multiple[$id]['id']);
    $menu_links_object_multiple[$id]['menu_name'] = $target_menu_name;
    if (isset($menu_links_object_multiple[$id]['parent']['value']) && !empty($menu_links_object_multiple[$id]['parent']['value'])) {
      $menu_links_object_multiple[$id]['parent']['value'] = $uuid_map[$menu_links_object_multiple[$id]['parent']['value']];
    }
  }
  return $menu_links_object_multiple;
}