Skip to content

Commit

Permalink
Merge pull request #46 from nthmedia/feature/add-without-container-op…
Browse files Browse the repository at this point in the history
…tions

menuHTML without div-container and outside UL
  • Loading branch information
alinistrate authored May 18, 2020
2 parents 870ebde + eacf5a3 commit 37309af
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .craftplugin
Original file line number Diff line number Diff line change
@@ -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"}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
93 changes: 50 additions & 43 deletions src/services/OlivemenusService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,7 +35,7 @@ class OlivemenusService extends Component
{
// Public Methods
// =========================================================================

public function getAllMenus($siteId) {
return OlivemenusRecord::find()
->where(['site_id' => $siteId])
Expand Down Expand Up @@ -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 '<p>' . Craft::t('olivemenus', 'A menu with this handle does not exist!') . '</p>';
return;
}

$menu_id = '';
$menu_class = '';
$ul_class = '';
$withoutContainer = false;
$withoutUl = false;

$localHTML .= '<div' .$menu_id. ' class="menu' .$menu_class. '">';
$localHTML .= '<ul class="' . $ul_class . '">';
foreach ( $menu_items as $menu_item ) {
$localHTML .= $this->getMenuItemHTML($menu_item, $config);
}
$localHTML .= '</ul>';
$localHTML .= '</div>';
} else {
$localHTML .= '<p>' . Craft::t('olivemenus', 'A menu with this handle does not exit!') . '</p>';
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 = '<ul class="' . $ul_class . '">' . $localHTML . '</ul>';
}

if ($withoutContainer !== true) {
$localHTML = '<div' . $menu_id . ' class="menu' . $menu_class . '">' . $localHTML . '</div>';
}

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'];

Expand Down Expand Up @@ -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
Expand All @@ -203,7 +210,7 @@ private function getMenuItemHTML($menu_item, $config) {
$menu_item_class .= ' current-menu-item';
}
}

$localHTML = '';
$localHTML .= '<li id="menu-item-' .$menu_item['id']. '" class="' .$menu_item_class. '">';

Expand Down

0 comments on commit 37309af

Please sign in to comment.