Multiple menu items workaround (Joomla 3.0)
Posted: 13 Jan 2013, 23:01
Situation: Joomla 3.0. Phocagalllery working great! Two gallery categories: Photos and Videos, each with their own categories. Two menu items: Photos and Videos.
When user clicks on Videos, the video categories are displayed. Great. PROBLEM: the links of those (video) categories refer to the photos menu item:
http://<site>/photos/category/4-video-2012
The result: when user clicks on this category, the category (4-video-2012) is displayed, but now the menu item Photos is active!..
The problem seems to be as follows: the link is built in
/components/com_phocagallery/views/categories/view.feed.php (line 91)
This calls function getCategoryRoute, found in
/administrator/components/com_phocagallery/libraries/phocagallery/path/route.php
It sets needles to category -> catid and categories. The last one is what we're looking for.
The function _findItem (same file) goes through all phocagallery menu items (here: 2) and if the view is right (categories) and id in query (empty) is same as id we look for (also empty.. so yes they are the same), it returns this menu item.
As the first menu item (Photos) is a match, it returns this as the (wrong) result.
Best fix would be to check if the subcategory is subcategory (or subsub or ..) of the menu item. For the time being, I came up with a quick fix, which seems to be working.
The fix is to check whether the menu item we are looking for, has the same ID as the active menu item.
Function _findItem:
// existing code
$menus = &JApplication::getMenu('site', array());
$items = $menus->getItems('component', 'com_phocagallery');
// new code
$active_item =& $menus->getActive();
$active_menuitemid = $active_item->id;
few lines below:
// old code:
if ((@$item->query['view'] == $needle) && (@$item->query['id'] == $id)) {
// new code:
if ((@$item->query['view'] == $needle) && (@$item->query['id'] == $id) && (@$item->id == $active_menuitemid)) {
May be there's a much simpler solution?
When user clicks on Videos, the video categories are displayed. Great. PROBLEM: the links of those (video) categories refer to the photos menu item:
http://<site>/photos/category/4-video-2012
The result: when user clicks on this category, the category (4-video-2012) is displayed, but now the menu item Photos is active!..
The problem seems to be as follows: the link is built in
/components/com_phocagallery/views/categories/view.feed.php (line 91)
This calls function getCategoryRoute, found in
/administrator/components/com_phocagallery/libraries/phocagallery/path/route.php
It sets needles to category -> catid and categories. The last one is what we're looking for.
The function _findItem (same file) goes through all phocagallery menu items (here: 2) and if the view is right (categories) and id in query (empty) is same as id we look for (also empty.. so yes they are the same), it returns this menu item.
As the first menu item (Photos) is a match, it returns this as the (wrong) result.
Best fix would be to check if the subcategory is subcategory (or subsub or ..) of the menu item. For the time being, I came up with a quick fix, which seems to be working.
The fix is to check whether the menu item we are looking for, has the same ID as the active menu item.
Function _findItem:
// existing code
$menus = &JApplication::getMenu('site', array());
$items = $menus->getItems('component', 'com_phocagallery');
// new code
$active_item =& $menus->getActive();
$active_menuitemid = $active_item->id;
few lines below:
// old code:
if ((@$item->query['view'] == $needle) && (@$item->query['id'] == $id)) {
// new code:
if ((@$item->query['view'] == $needle) && (@$item->query['id'] == $id) && (@$item->id == $active_menuitemid)) {
May be there's a much simpler solution?