Jaxel
Well-known member
Okay... so a while back, Kier said he would look into the feasibility of making the "Home" button a real tab... well I've already done the work! Its actually pretty simple and I recommend it gets added to XenForo's base code...
EDIT TEMPLATE: navigation
find:
replace with:
As you can see, this new replacement looks for a variable $homeTabs... if the variable doesn't exist, then it reverts to the classic Home tab that we have with the current version of XenForo. Once thats done... all we need to do is tell XenForo how to handle the $homeTabs variable...
EDIT FILE: /library/XenForo/Dependencies/Public.php
find: (in protected function _getNavigationContainerParams)
replace with:
You'll notice: XenForo_CodeEvent::fire('navigation_tabs', array(&$homeTabs, &$extraTabs, $selectedTabId));
has a new reference called "$homeTabs"... this is an update to the Code Event Listener, and thusly mod writers will have to update their navtab listener classes with this new variable. Yes, this is troublesome, but at the moment there are not that many mods released yet, so the transition should be relatively simple. The sooner this change of mine is included into the base XenForo installation , the easier the transition will be...
EDIT FILE: /library/XenForo/ViewRenderer/HtmlPublic.php
find: (in public function renderContainer)
add below:
THATS IT! Now, a mod need only add a tab to $homeTabs instead of $extraTabs if they want to replace the home link! Now that the work is already done... there is no reason this addition shouldn't be made to XenForo. Plus I made this solution as elegant as I could, and it conforms to the XenForo coding style.
EDIT TEMPLATE: navigation
find:
Code:
<!-- home -->
<li class="navTab home PopupClosed"><a href="{$homeLink}" class="navLink">{xen:phrase home}</a></li>
Code:
<!-- home tabs -->
<xen:if is="{$homeTabs}">
<xen:foreach loop="$homeTabs" key="$homeTabId" value="$homeTab">
<xen:if is="{$homeTab.linksTemplate}">
<li class="navTab $extraTabId {xen:if $homeTab.selected, 'selected', 'Popup PopupControl PopupClosed'}">
<a href="{$homeTab.href}" class="navLink">{$homeTab.title}</a>
<a href="{$homeTab.href}" class="SplitCtrl" rel="Menu"></a>
<div class="{xen:if {$homeTab.selected}, 'tabLinks', 'Menu JsOnly tabMenu'}">
<div class="primaryContent menuHeader">
<h3>{$homeTab.title}</h3>
<div class="muted">{xen:phrase quick_links}</div>
</div>
{xen:raw $homeTab.linksTemplate}
</div>
</li>
<xen:else />
<li class="navTab PopupClosed"><a href="{$homeTab.href}" class="navLink">{$homeTab.title}</a></li>
</xen:if>
</xen:foreach>
<xen:else />
<li class="navTab home PopupClosed"><a href="{$homeLink}" class="navLink">{xen:phrase home}</a></li>
</xen:if>
EDIT FILE: /library/XenForo/Dependencies/Public.php
find: (in protected function _getNavigationContainerParams)
Code:
$extraTabs = array();
XenForo_CodeEvent::fire('navigation_tabs', array(&$extraTabs, $selectedTabId));
if (!empty($extraTabs[$selectedTabId]))
{
$selectedTab = $extraTabs[$selectedTabId];
}
else if (!empty($tabs[$selectedTabId]))
{
$selectedTab = $tabs[$selectedTabId];
}
else
{
$selectedTabId = '';
$selectedTab = false;
}
$options = XenForo_Application::get('options');
if ($options->homePageUrl)
{
$homeLink = $options->homePageUrl;
$logoLink = ($options->logoLink ? $homeLink : XenForo_Link::buildPublicLink('full:index'));
}
else
{
$homeLink = XenForo_Link::buildPublicLink('full:index');
$logoLink = $homeLink;
}
return array(
'tabs' => $tabs,
'extraTabs' => $extraTabs,
'selectedTab' => $selectedTab,
'selectedTabId' => $selectedTabId,
'homeLink' => $homeLink,
'logoLink' => $logoLink,
);
Code:
$homeTabs = array();
$extraTabs = array();
XenForo_CodeEvent::fire('navigation_tabs', array(&$homeTabs, &$extraTabs, $selectedTabId));
if (!empty($extraTabs[$selectedTabId]))
{
$selectedTab = $extraTabs[$selectedTabId];
}
else if (!empty($homeTabs[$selectedTabId]))
{
$selectedTab = $homeTabs[$selectedTabId];
}
else if (!empty($tabs[$selectedTabId]))
{
$selectedTab = $tabs[$selectedTabId];
}
else
{
$selectedTabId = '';
$selectedTab = false;
}
$options = XenForo_Application::get('options');
if ($options->homePageUrl)
{
$homeLink = $options->homePageUrl;
$logoLink = ($options->logoLink ? $homeLink : XenForo_Link::buildPublicLink('full:index'));
}
else
{
$homeLink = XenForo_Link::buildPublicLink('full:index');
$logoLink = $homeLink;
}
return array(
'tabs' => $tabs,
'homeTabs' => $homeTabs,
'extraTabs' => $extraTabs,
'selectedTab' => $selectedTab,
'selectedTabId' => $selectedTabId,
'homeLink' => $homeLink,
'logoLink' => $logoLink,
);
has a new reference called "$homeTabs"... this is an update to the Code Event Listener, and thusly mod writers will have to update their navtab listener classes with this new variable. Yes, this is troublesome, but at the moment there are not that many mods released yet, so the transition should be relatively simple. The sooner this change of mine is included into the base XenForo installation , the easier the transition will be...
EDIT FILE: /library/XenForo/ViewRenderer/HtmlPublic.php
find: (in public function renderContainer)
Code:
if (!empty($params['extraTabs']))
{
foreach ($params['extraTabs'] AS &$extraTab)
{
if (!empty($extraTab['linksTemplate']))
{
$extraTab['linksTemplate'] = $this->createTemplateObject($extraTab['linksTemplate'], $extraTab);
}
}
}
Code:
if (!empty($params['homeTabs']))
{
foreach ($params['homeTabs'] AS &$homeTab)
{
if (!empty($homeTab['linksTemplate']))
{
$homeTab['linksTemplate'] = $this->createTemplateObject($homeTab['linksTemplate'], $homeTab);
}
}
}
THATS IT! Now, a mod need only add a tab to $homeTabs instead of $extraTabs if they want to replace the home link! Now that the work is already done... there is no reason this addition shouldn't be made to XenForo. Plus I made this solution as elegant as I could, and it conforms to the XenForo coding style.
Upvote
10