/** * @param Fraym\Menu\Entity\MenuItem $menuItem * @param bool $withProtocol * @return string */ public function buildFullUrl($menuItem, $withProtocol = false) { if ($menuItem->getCurrentTranslation() && $menuItem->getCurrentTranslation()->externalUrl) { return $menuItem->getCurrentTranslation()->url; } $url = rtrim($this->getCurrentDomain(), '/') . '/' . ($menuItem->getCurrentTranslation() ? ltrim($menuItem->getCurrentTranslation()->url, '/') : ''); if ($withProtocol === true) { $url = ($menuItem->https ? 'https://' : 'http://') . $url; } return $url; }
/** * */ private function addMenuItem() { $menu = $this->request->post('menu'); if ($menu !== null) { $newMenuItem = new \Fraym\Menu\Entity\MenuItem(); try { foreach ($menu['translations'] as $k => $translation) { if (empty($translation['title'])) { unset($menu['translations'][$k]); } } $newMenuItem->updateEntity($menu); $menuItemsTranslations = array(); foreach ($newMenuItem->translations as $translation) { $menuItemsTranslations[$translation->locale->id] = $translation->id; } $this->response->sendAsJson(array('error' => false, 'menuId' => $newMenuItem->id, 'translations' => $menuItemsTranslations)); } catch (\Exception $e) { $this->response->sendAsJson(array('error' => true, 'message' => $e->getMessage())); } } }