Copies a menu into another one.

@param string $id The menu's ID to copy
@param string $id_menu_to The target menu's ID
@param array $cfg
@return null|string The new ID
765791
public function copy(string $id_menu, string $id_menu_to, array $cfg): ?string
  {
    if (
      \bbn\str::is_uid($id_menu) &&
      \bbn\str::is_uid($id_menu_to) &&
      ($bits = $this->pref->get_full_bits($id_menu)) &&
      ($id = $this->add($id_menu_to, $cfg)) &&
      $this->_clone($id_menu_to, $bits, $id)
    ){
      return $id;
    }
    return null;
  }
492465
private function loadCategory($id = null, $languageId = null, $viewName, $params = [])
    {
        $category = (!empty($id)) ? Category::findOne($id) : new Category();
        $categoryTranslation = (!empty($id)) ? CategoryTranslation::find()->where([
            'category_id' => $id,
            'language_id' => $languageId
        ])->one() : new CategoryTranslation();

        $categoryTranslation = $categoryTranslation ?? new CategoryTranslation();

        if (Yii::$app->request->isPost) {
            ($category->isNewRecord) ? $this->trigger(self::EVENT_BEFORE_CREATE_CATEGORY) :
                $this->trigger(self::EVENT_BEFORE_EDIT_CATEGORY);

            $post = Yii::$app->request->post();

            $category->load($post);
            $category->parent_id = (!empty($category->parent_id)) ? $category->parent_id : null;
            $categoryTranslation->load($post);

            if ($category->validate()) {
                $eventName = $category->isNewRecord ? self::EVENT_AFTER_CREATE_CATEGORY : self::EVENT_AFTER_EDIT_CATEGORY;

                $category->save();

                if (empty($categoryTranslation->seoUrl)) $categoryTranslation->seoUrl = Inflector::slug($categoryTranslation->title);

                $categoryTranslation->category_id = $category->id;
                $categoryTranslation->language_id = $languageId;

                if ($categoryTranslation->validate()) {
                    $categoryTranslation->save();

                    $this->trigger($eventName, new CategoryEvent(['id' => $category->id]));

                    Yii::$app->getSession()->setFlash('success', 'The category has been successfully modified.');
                    return $this->redirect([$viewName, 'id' => $category->id, 'languageId' => $languageId]);
                }
            }
        }

        return $this->render('save', [
            'viewName' => $viewName,
            'params' => array_merge([
                'languages' => Language::findAll(['active' => true]),
                'maxPosition' => Category::find()->where(['parent_id' => $category->parent_id])->max('position') + 1 ?? 1,
                'category' => $category,
                'categoryTranslation' => $categoryTranslation,
                'categories' => Category::find()->with('translations')->all(),
                'selectedLanguage' => Language::findOne($languageId),
            ], $params)
        ]);
    }
1000923
protected function createMenuItem(string $id, array $options): ?ItemInterface
    {
        return $this->factory->createItem($id, $options);
    }
254551
public static function getMenu($appid, $pid = 0) {
		$button = static::find()->where(['appid' => $appid, 'conditional' => 0, 'pid' => $pid])->select('id, type, name, key, url, media_id')->orderby('list_order, created_at')->asArray()->all();

		foreach($button as $index => $_button) {
			$button[$index]['sub_button'] = static::getMenu($appid, $_button['id']);
			unset($_button['id']);
		}

		return $button;
	}
793457
public function setMenuId( $menuId )
    {
        $this->menuId = empty( $menuId ) ? null : (int) $menuId;

        if ( null !== $this->_menu &&
             $this->_menu->id != $this->menuId )
        {
            $this->_menu = null;
        }

        return $this;
    }
516958
public static MenuItem createFromExistingWithId(MenuItem selected, int newId) {
        return visitWithResult(selected, new AbstractMenuItemVisitor<MenuItem>() {
            @Override
            public void visit(AnalogMenuItem item) {
                setResult(AnalogMenuItemBuilder.anAnalogMenuItemBuilder()
                        .withExisting(item)
                        .withId(newId)
                        .menuItem()
                );
            }

            @Override
            public void visit(BooleanMenuItem item) {
                setResult(BooleanMenuItemBuilder.aBooleanMenuItemBuilder()
                        .withExisting(item)
                        .withId(newId)
                        .menuItem()
                );
            }

            @Override
            public void visit(EnumMenuItem item) {
                setResult(EnumMenuItemBuilder.anEnumMenuItemBuilder()
                        .withExisting(item)
                        .withId(newId)
                        .menuItem()
                );
            }

            @Override
            public void visit(SubMenuItem item) {
                setResult(SubMenuItemBuilder.aSubMenuItemBuilder()
                        .withExisting(item)
                        .withId(newId)
                        .menuItem()
                );
            }

            @Override
            public void visit(TextMenuItem item) {
                setResult(TextMenuItemBuilder.aTextMenuItemBuilder()
                        .withExisting(item)
                        .withId(newId)
                        .menuItem()
                );
            }

            @Override
            public void visit(RemoteMenuItem item) {
                setResult(RemoteMenuItemBuilder.aRemoteMenuItemBuilder()
                        .withExisting(item)
                        .withId(newId)
                        .menuItem()
                );
            }

            @Override
            public void visit(FloatMenuItem item) {
                setResult(FloatMenuItemBuilder.aFloatMenuItemBuilder()
                        .withExisting(item)
                        .withId(newId)
                        .menuItem()
                );
            }
            @Override
            public void visit(ActionMenuItem item) {
                setResult(ActionMenuItemBuilder.anActionMenuItemBuilder()
                        .withExisting(item)
                        .withId(newId)
                        .menuItem()
                );
            }
        }).orElse(null);
    }
1042493
public function delete(string $id = null): void
    {
        $this->request->allowMethod(['post', 'delete']);
        $menu = $this->Menus->get($id);
        if ($this->Menus->delete($menu)) {
            $this->Flash->success((string)__('The menu has been deleted.'));
        } else {
            $this->Flash->error((string)__('The menu could not be deleted. Please, try again.'));
        }

        $this->redirect(['action' => 'index']);
    }
1070486
public function edit($cfg, $id_user=false)
	{
	  $u =& $this->class_cfg['arch']['users'];
    $fields = array_unique(array_values($this->class_cfg['arch']['users']));
    $cfg[$u['active']] = 1;
    foreach ( $cfg as $k => $v ){
      if ( !\in_array($k, $fields) ){
        unset($cfg[$k]);
      }
    }
    if ( !$id_user && isset($cfg[$u['id']]) ){
      $id_user = $cfg[$u['id']];
    }
    if ( $id_user && (
            !isset($cfg[$this->class_cfg['arch']['users']['email']]) ||
            bbn\str::is_email($cfg[$this->class_cfg['arch']['users']['email']])
          )
    ){
      if ( $this->db->update($this->class_cfg['tables']['users'], $cfg, [
        $u['id'] => $id_user
      ]) ){
        $cfg['id'] = $id_user;
        return $cfg;
      }
    }
		return false;
	}
1027426
public function add_link(string $id_option, string $id_link): ?string
  {
    $id = $this->db->select_one($this->class_cfg['table'], $this->fields['id'], [
      $this->fields['id_user'] => $this->id_user,
      $this->fields['id_option'] => $id_option
    ]);
    if ( $id ){
      if ( $this->db->update($this->class_cfg['table'], [
        $this->fields['id_link'] => $id_link
      ], ['id' => $id]) ){
        return $id;
      }
    }
    else if ( $this->db->insert($this->class_cfg['table'], [
      $this->fields['id_user'] => $this->id_user,
      $this->fields['id_option'] => $id_option,
      $this->fields['id_link'] => $id_link
    ]) ){
      return $this->db->last_id();
    }
    return null;
  }
848768
public function cache($id = null, $tags = [])
    {
        $this->_shouldCache = $id === false ? false : true;
        $this->_cacheId = is_string($id) ? $id : $this->_cacheId;
        $this->_cacheTags = $tags ? (array) $tags : $this->_cacheTags;

        return $this;
    }
630907
protected function addChild(string $id, string $parent): ?Fluent
    {
        $node = $this->descendants($this->items, $parent);

        // it might be possible parent is not defined due to ACL, in this
        // case we should simply ignore this request as child should
        // inherit parent ACL access.
        if (! isset($node)) {
            return null;
        }

        $item = $node->get('childs');
        $item[$id] = $this->toFluent($id);

        $node->childs($item);

        return $item[$id];
    }
1309657
public function edit($id)
    {
        $this->loadModel('Menu.MenuLinks');
        $this->loadModel('Content.Contents');
        $link = $this->MenuLinks->get($id, ['contain' => ['Menus']]);

        if (!empty($this->request->data)) {
            $link = $this->MenuLinks->patchEntity($link, $this->request->data, [
                'fieldList' => [
                    'title',
                    'url',
                    'description',
                    'target',
                    'expanded',
                    'active',
                    'activation',
                    'status'
                ]
            ]);

            if ($this->MenuLinks->save($link, ['associated' => false])) {
                $this->Flash->success(__d('menu', 'Link has been updated'));
                $this->redirect($this->referer());
            } else {
                $this->Flash->danger(__d('menu', 'Link could not be updated, please check your information'));
            }
        }

        $contentLinks = [];
        $contents = $this->Contents
            ->find()
            ->select(['id', 'slug', 'content_type_slug', 'title'])
            ->all();
        foreach ($contents as $content) {
            $contentLinks[$content->get('url')] = __d('menu', '{0} [{1}]', $content->title, $content->content_type_slug);
        }

        $this->title(__d('menu', 'Editing Link'));
        $this->set(compact('link', 'contentLinks'));
        $this->Breadcrumb
            ->push('/admin/menu/manage')
            ->push(__d('menu', 'Editing menu'), ['plugin' => 'Menu', 'controller' => 'manage', 'action' => 'edit', $link->menu_id])
            ->push(__d('menu', 'Links'), ['plugin' => 'Menu', 'controller' => 'links', 'action' => 'menu', $link->menu_id])
            ->push(__d('menu', 'Editing link'), '#');
    }
123453
public function delete($id)
    {
        $this->loadModel('Menu.MenuLinks');
        $link = $this->MenuLinks->get($id);
        $this->MenuLinks->addBehavior('Tree', ['scope' => ['menu_id' => $link->menu_id]]);
        $this->MenuLinks->removeFromTree($link);

        if ($this->MenuLinks->delete($link)) {
            $this->Flash->success(__d('menu', 'Link successfully removed!'));
        } else {
            $this->Flash->danger(__d('menu', 'Link could not be removed, please try again'));
        }

        $this->title(__d('menu', 'Delete Link'));
        $this->redirect($this->referer());
    }
1206162
public function getChild(string $id)
    {
        $menuItem = $this->menuItem->getChild($id);

        return $menuItem ? $this->generateMenuItem($menuItem) : null;
    }
128081
public function add_shortcut(string $id): ?string
  {
    if (
      ($bit = $this->pref->get_bit($id, false)) &&
      ($id_option = $this->from_path('shortcuts')) &&
      ($c = $this->pref->get_class_cfg())
    ){
      if ( $id_menu = $this->pref->get_by_option($id_option) ){
        $id_menu = $id_menu[$c['arch']['user_options']['id']];
      }
      else {
        $id_menu = $this->pref->add($id_option, [$c['arch']['user_options']['text'] => _('Shortcuts')]);
      }
      if (
        !empty($id_menu) &&
        ($arch = $c['arch']['user_options_bits'])
      ){
        if (
          ($bits = $this->pref->get_bits($id_menu, false, false)) &&
          ( \bbn\x::find($bits, [$arch['id_option'] => $bit[$arch['id_option']]]) !== false)
        ){
          return null;
        }
        return $this->pref->add_bit($id_menu, [
          $arch['id_option'] => $bit[$arch['id_option']],
          $arch['text'] => $bit[$arch['text']],
          $arch['cfg'] => $bit[$arch['cfg']],
          $arch['num'] => $this->pref->next_bit_num($id_menu) ?: 1
        ]);
      }
    }
    return null;
  }
119201
public function set_cfg(string $id = null, array $cfg = null): int
  {
    if ( null !== $cfg ){
      $cfg = $this->get_cfg(null, $cfg);
      $config = json_encode($cfg);
    }
    else{
      $config = null;
    }
    return $this->db->update($this->class_cfg['table'], [
      $this->fields['cfg'] => $config
    ], [
      $this->fields['id'] => $id
    ]);
  }
696822
public function add(string $id_option = null, array $cfg): ?string
  {
    return (
      ($id_option = $this->_get_id_option($id_option)) &&
      $this->_insert($id_option, $cfg)
    ) ? $this->db->last_id() : null;
  }