Instantly share code, notes, and snippets.
Created
March 14, 2015 05:36
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save sanjeevshrestha/8ebcb49bcaf8c858c355 to your computer and use it in GitHub Desktop.
Making Joomla 3.4.x administrator menu 2 column
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @author Sanjeev Shrestha <sanjeev@joomlaguru.com.np> | |
* 14/03/2015 | |
* Add a class to Menu Node For the menu in the administrator/mod_menu/tmpl/default_enabled.php | |
* Here I am making the admin components menu 2 column | |
*/ | |
/** | |
* Add a class to 'components' menu node creator in file administrator/mod_menu/tmpl/default_enabled.php | |
* Replace $menu->addChild(new JMenuNode(JText::_('MOD_MENU_COMPONENTS'), '#'), true); with $menu->addChild(new JMenuNode(JText::_('MOD_MENU_COMPONENTS'), '#','components'), true); | |
* | |
*/ | |
// File administrator/mod_menu/tmpl/default_enabled.php | |
/* | |
* Components Submenu | |
*/ | |
// Get the authorised components and sub-menus. | |
$components = ModMenuHelper::getComponents(true); | |
// Check if there are any components, otherwise, don't render the menu | |
if ($components) | |
{ | |
$menu->addChild(new JMenuNode(JText::_('MOD_MENU_COMPONENTS'), '#','components'), true); | |
foreach ($components as &$component) | |
{ | |
if (!empty($component->submenu)) | |
{ | |
// This component has a db driven submenu. | |
$menu->addChild(new JMenuNode($component->text, $component->link, $component->img), true); | |
foreach ($component->submenu as $sub) | |
{ | |
$menu->addChild(new JMenuNode($sub->text, $sub->link, $sub->img)); | |
} | |
$menu->getParent(); | |
} | |
else | |
{ | |
$menu->addChild(new JMenuNode($component->text, $component->link, $component->img)); | |
} | |
} | |
$menu->getParent(); | |
} | |
//File administrator/mod_menu/menu.php | |
/** | |
* Modify the JAdminCSSMenu RenderMenu Method for following modification | |
* Change $depth=1; to $depth=0; | |
* Change $depth++ to $depth+1 | |
*/ | |
public function renderMenu($id = 'menu', $class = '') | |
{ | |
$depth = 0; | |
if (!empty($id)) | |
{ | |
$id = 'id="' . $id . '"'; | |
} | |
if (!empty($class)) | |
{ | |
$class = 'class="' . $class . '"'; | |
} | |
// Recurse through children if they exist | |
while ($this->_current->hasChildren()) | |
{ | |
echo "<ul " . $id . " " . $class . ">\n"; | |
foreach ($this->_current->getChildren() as $child) | |
{ | |
$this->_current = & $child; | |
$this->renderLevel($depth+1); | |
} | |
echo "</ul>\n"; | |
} | |
if ($this->_css) | |
{ | |
// Add style to document head | |
JFactory::getDocument()->addStyleDeclaration($this->_css); | |
} | |
} | |
/** | |
* Modify the JAdminCssMenu class render level method to include the current class in the node | |
* Change echo '<ul' . $id . ' class="dropdown-menu menu-component">' . "\n"; | |
* to | |
* echo '<ul' . $id . ' class="dropdown-menu menu-component '.$this->_current->class.'">' . "\n"; | |
* Change the $depth++ to $depth+1 | |
* | |
* Change | |
* if ($this->_current->hasChildren() && $this->_current->class) | |
* To | |
* if ($depth>1 && $this->_current->hasChildren() && $this->_current->class) | |
* | |
* As shown in following gist | |
*/ | |
public function renderLevel($depth) | |
{ | |
// Build the CSS class suffix | |
$class = ''; | |
if ($this->_current->hasChildren()) | |
{ | |
$class = ' class="dropdown"'; | |
} | |
if ($this->_current->class == 'separator') | |
{ | |
$class = ' class="divider"'; | |
} | |
if ($depth>1 && $this->_current->hasChildren() && $this->_current->class) | |
{ | |
$class = ' class="dropdown-submenu"'; | |
} | |
if ($this->_current->class == 'disabled') | |
{ | |
$class = ' class="disabled"'; | |
} | |
// Print the item | |
echo "<li" . $class . ">"; | |
// Print a link if it exists | |
$linkClass = array(); | |
$dataToggle = ''; | |
$dropdownCaret = ''; | |
if ($this->_current->hasChildren()) | |
{ | |
$linkClass[] = 'dropdown-toggle'; | |
$dataToggle = ' data-toggle="dropdown"'; | |
if (!$this->_current->getParent()->hasParent()) | |
{ | |
$dropdownCaret = ' <span class="caret"></span>'; | |
} | |
} | |
if ($this->_current->link != null && $this->_current->getParent()->title != 'ROOT') | |
{ | |
$iconClass = $this->getIconClass($this->_current->class); | |
if (!empty($iconClass)) | |
{ | |
$linkClass[] = $iconClass; | |
} | |
} | |
// Implode out $linkClass for rendering | |
$linkClass = ' class="' . implode(' ', $linkClass) . '"'; | |
if ($this->_current->link != null && $this->_current->target != null) | |
{ | |
echo "<a" . $linkClass . " " . $dataToggle . " href=\"" . $this->_current->link . "\" target=\"" . $this->_current->target . "\" >" | |
. $this->_current->title . $dropdownCaret . "</a>"; | |
} | |
elseif ($this->_current->link != null && $this->_current->target == null) | |
{ | |
echo "<a" . $linkClass . " " . $dataToggle . " href=\"" . $this->_current->link . "\">" . $this->_current->title . $dropdownCaret . "</a>"; | |
} | |
elseif ($this->_current->title != null) | |
{ | |
echo "<a" . $linkClass . " " . $dataToggle . ">" . $this->_current->title . $dropdownCaret . "</a>"; | |
} | |
else | |
{ | |
echo "<span></span>"; | |
} | |
// Recurse through children if they exist | |
while ($this->_current->hasChildren()) | |
{ | |
if ($this->_current->class) | |
{ | |
$id = ''; | |
if (!empty($this->_current->id)) | |
{ | |
$id = ' id="menu-' . strtolower($this->_current->id) . '"'; | |
} | |
echo '<ul' . $id . ' class="dropdown-menu menu-component '.$this->_current->class.'">' . "\n"; //This will add a current class to the <ul> as set in the node creator | |
} | |
else | |
{ | |
echo '<ul class="dropdown-menu">' . "\n"; | |
} | |
foreach ($this->_current->getChildren() as $child) | |
{ | |
$this->_current = & $child; | |
$this->renderLevel($depth+1); | |
} | |
echo "</ul>\n"; | |
} | |
echo "</li>\n"; | |
} | |
?> | |
/**Custom CSS for two column components menu | |
*/ | |
.dropdown-menu.components | |
{ | |
min-width:500px; | |
} | |
.dropdown-menu.components>li | |
{ | |
float:left; | |
width:49%; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment