diff --git a/.craftplugin b/.craftplugin index 3c04dc9..c4f0f97 100644 --- a/.craftplugin +++ b/.craftplugin @@ -1 +1 @@ -{"pluginName":Menus","pluginDescription":"Olive Studio","pluginVersion":"1.1.10","pluginAuthorName":"Olivestudio","pluginVendorName":"olivestudio","pluginAuthorUrl":"http://www.olivestudio.net/","pluginAuthorGithub":"OliveStudio","codeComments":"yes","pluginComponents":["controllers","cpsection","models","records","services","variables"],"consolecommandName":"","controllerName":"","cpsectionName":"","elementName":"","fieldName":"","modelName":"","purchasableName":"","recordName":"","serviceName":"","taskName":"","utilityName":"","widgetName":"","apiVersion":"api_version_3_0"} +{"pluginName":Menus","pluginDescription":"Olive Studio","pluginVersion":"1.2.0","pluginAuthorName":"Olivestudio","pluginVendorName":"olivestudio","pluginAuthorUrl":"http://www.olivestudio.net/","pluginAuthorGithub":"OliveStudio","codeComments":"yes","pluginComponents":["controllers","cpsection","models","records","services","variables"],"consolecommandName":"","controllerName":"","cpsectionName":"","elementName":"","fieldName":"","modelName":"","purchasableName":"","recordName":"","serviceName":"","taskName":"","utilityName":"","widgetName":"","apiVersion":"api_version_3_0"} diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c59221..391ffaf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,3 +66,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - migration/down for multi-site - set default site ID for multi-site migrations #44 - fix URL routing for multi-site (index and create) #43 + +## 1.2.0 - 2020-05-18 +### Added +- extra config options for HTML output: without-container and without-ul diff --git a/composer.json b/composer.json index ec91a89..aaeaa4f 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "olivestudio/craft-olivemenus", "description": "A powerful menus plugin for Craft 3 built for the need of simplicity and flexibility", "type": "craft-plugin", - "version": "1.1.10", + "version": "1.2.0", "keywords": [ "craft", "cms", diff --git a/src/services/OlivemenusService.php b/src/services/OlivemenusService.php index 5dd17e8..f93d75c 100644 --- a/src/services/OlivemenusService.php +++ b/src/services/OlivemenusService.php @@ -10,14 +10,13 @@ namespace olivestudio\olivemenus\services; -use olivestudio\olivemenus\models\OlivemenusModel; -use olivestudio\olivemenus\Olivemenus; -use olivestudio\olivemenus\records\OlivemenusRecord; - use Craft; use craft\base\Component; use craft\elements\Entry; use craft\elements\Category; +use olivestudio\olivemenus\models\OlivemenusModel; +use olivestudio\olivemenus\Olivemenus; +use olivestudio\olivemenus\records\OlivemenusRecord; /** * OlivemenusService Service @@ -36,7 +35,7 @@ class OlivemenusService extends Component { // Public Methods // ========================================================================= - + public function getAllMenus($siteId) { return OlivemenusRecord::find() ->where(['site_id' => $siteId]) @@ -98,56 +97,64 @@ public function saveMenu(OlivemenusModel $model) { return $save; } - // Frotend Methods + // Front-end Methods // ========================================================================= public function getMenuHTML($handle = false, $config ) { - if ($handle) { - $localHTML = ''; - - $menu = $this->getMenuByHandle($handle); - - if ($menu !== NULL) { - $menu_id = ''; - $menu_class = ''; - $ul_class = ''; - $menu_items = Olivemenus::$plugin->olivemenuItems->getMenuItems($menu->id); - - if (!empty($config)) { - if (isset($config['menu-id'])) { - $menu_id = ' id="' .$config['menu-id']. '"'; - } - if (isset($config['menu-class'])) { - $menu_class .= ' ' . $config['menu-class']; - } - if (isset($config['ul-class'])) { - $ul_class = $config['ul-class']; - } - } + if ($handle === false || ($menu = $this->getMenuByHandle($handle)) === null) { + echo '

' . Craft::t('olivemenus', 'A menu with this handle does not exist!') . '

'; + return; + } + + $menu_id = ''; + $menu_class = ''; + $ul_class = ''; + $withoutContainer = false; + $withoutUl = false; - $localHTML .= ''; - $localHTML .= ''; - $localHTML .= ''; - } else { - $localHTML .= '

' . Craft::t('olivemenus', 'A menu with this handle does not exit!') . '

'; + if (!empty($config)) { + if (isset($config['menu-id'])) { + $menu_id = ' id="' .$config['menu-id']. '"'; + } + if (isset($config['menu-class'])) { + $menu_class .= ' ' . $config['menu-class']; + } + if (isset($config['ul-class'])) { + $ul_class = $config['ul-class']; } - echo $localHTML; + if (isset($config['without-container'])) { + $withoutContainer = $config['without-container']; + } + if (isset($config['without-ul'])) { + $withoutUl = $config['without-ul']; + } + } + + $localHTML = ''; + + $menu_items = Olivemenus::$plugin->olivemenuItems->getMenuItems($menu->id); + foreach ($menu_items as $menu_item) { + $localHTML .= $this->getMenuItemHTML($menu_item, $config); + } + + if ($withoutUl !== true) { + $localHTML = ''; } + + if ($withoutContainer !== true) { + $localHTML = '' . $localHTML . ''; + } + + echo $localHTML; } private function getMenuItemHTML($menu_item, $config) { $menu_item_url = ''; - $menu_class = ''; $ul_class = ''; $menu_item_class = 'menu-item'; - $entry_id = $menu_item['entry_id']; $custom_url = $menu_item['custom_url']; $class = $menu_item['class']; $class_parent = $menu_item['class_parent']; - + $data_attributes = ''; $data_json = $menu_item['data_json']; @@ -188,7 +195,7 @@ private function getMenuItemHTML($menu_item, $config) { $data_item = explode(':', $data_item); $data_attributes .= trim($data_item[0]) . '="' .trim($data_item[1]). '"'; } - + } //extract target option @@ -203,7 +210,7 @@ private function getMenuItemHTML($menu_item, $config) { $menu_item_class .= ' current-menu-item'; } } - + $localHTML = ''; $localHTML .= '