<div class="emb-menuinput"> <?php /** * The form input for a menuitem without begin/end form */ $model = $viewParams['menuModel']; $isNew = $model->getIsNewRecord(); $currentmenuOnlyChecked = $isNew ? true : (bool) $model->menuid; //default true if new record $maxDepthHtmlOptions = array('size' => 2, 'maxlength' => 1); if (!EMBNestedConfigUtil::isEmptyNestedConfig($model->nestedconfig)) { $maxDepthHtmlOptions['readonly'] = true; $maxDepthHint = Yii::t('MenubuilderModule.messages', 'Editable if no items assigned'); } else { $maxDepthHint = ''; } echo $form->hiddenField($model, 'menuid'); ?> <p class="note"><?php echo Yii::t('MenubuilderModule.messages', 'Fields with <span class="required">*</span> are required.'); ?> </p> <?php if ($this->menuFieldAllowed('menuid')) { ?> <div class="row"> <?php echo $form->labelEx($model, 'menuid'); ?> <?php
public function afterDelete($event) { list($menuId, $menuitemId, $insertBefore) = $this->decodeAttributeValue(); if (!empty($menuitemId)) { $this->initMenuData(); if (!empty($this->_menu)) { $nestedConfig = $this->_menu->nestedconfig; $this->_menu->nestedconfig = EMBNestedConfigUtil::removeId($nestedConfig, $this->_menuitemId); $this->_menu->save(); } if (!empty($this->_menuItem)) { $this->_menuItem->delete(); } } }
/** * Remove unused nested ids * Maybe this happens when in a cms a page with a menuitem is deleted * * @param null $menuId */ public function cleanUpNestedConfig($menuId = null) { $menus = $this->loadMenus(true, null, null, true); if (!empty($menus)) { $nestedItems = array(); $allItems = array(); //get all nested and all menuitemids in every menu foreach ($menus as $menu) { if (isset($menuId) && $menuId != $menu->menuid) { continue; } $nestedConfig = $menu->nestedconfig; $nestedItems[$menu->menuid] = array_merge($nestedItems, EMBNestedConfigUtil::extractExistingIds($nestedConfig)); $menuItems = $this->loadMenuItems($menuId, true, null, null, true); if (!empty($menuItems)) { foreach ($menuItems as $menuItem) { if (!in_array($menuItem->itemid, $allItems)) { $allItems[] = $menuItem->itemid; } } } } foreach ($menus as $menu) { if (isset($nestedItems[$menu->menuid])) { $removed = false; foreach ($nestedItems[$menu->menuid] as $nestedItemId) { if (!in_array($nestedItemId, $allItems)) { $menu->nestedconfig = EMBNestedConfigUtil::removeId($menu->nestedconfig, $nestedItemId); $removed = true; } } if ($removed) { $menu->save(); } } } } }