Implemented In addition to $extraTabs, lets have a $homeTabs

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:
Code:
		<!-- home -->
		<li class="navTab home PopupClosed"><a href="{$homeLink}" class="navLink">{xen:phrase home}</a></li>
replace with:
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>
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)
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,
		);
replace with:
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,
		);
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)
Code:
		if (!empty($params['extraTabs']))
		{
			foreach ($params['extraTabs'] AS &$extraTab)
			{
				if (!empty($extraTab['linksTemplate']))
				{
					$extraTab['linksTemplate'] = $this->createTemplateObject($extraTab['linksTemplate'], $extraTab);
				}
			}
		}
add below:
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
This suggestion has been implemented. Votes are no longer accepted.
Jaxel I sincerely hope this changes make it to the gold. It will allow enormous flexibility to moders and to have a real portal.

I'm wondering with that code, what happens if another modification also makes use of the $homeTabs? It looks like it would show both. How does the code decide which one is first? And more eimportantly, wouldn't it be problematic for later having the forums at /forum? if /index is being fought between two+ mods?
Yes, it would show both... it decides which one is first by the listener priority, which can be modified.
 
I don't get why we can't just put a link to whatever we want in the home tab and change the name of the link to whatever we like?

Jaxel, and many other developers, try to keep "template hacking" to a minimum.
They know the heartaches that come from supporting their creations when alot of functionality is left to individual admins hacking code.
and then xenforo releases another version.
the template hacks break.
and more support needed.
etc.
 
Now truly, I'm not a coder, so I really don't see much of a difference in calling it either $homeTabs or $extraTabs, unless there is a complete style difference.

Thanks for the tip -- yeah, I'm not a coder either so when I see a page-long explanation for how to change a link, it freaks me out a little. I didn't think things were going to be that complicated.

Jaxel, and many other developers, try to keep "template hacking" to a minimum.

Oh, I do get that he's helping -- I wasn't expressing any of that at him.
 
I have implemented something like this for the next release. The approach is a bit different though. Importantly, it maintains compatibility with anywhere that is adding a tab. You then choose the "position" of the tab (home, middle, or end currently); this approach allows more flexibility while maintaining backwards compatibility.

If a user has an explicit home page URL entered, the "home" button will always appear and link to that page. If they don't enter a URL, then "home" will not appear and it will fall back to the first of the tabs in the home position; if there are none, it will use the forum tab as the home.
 
It was included in Beta 4: http://xenforo.com/community/threads/xenforo-1-0-0-beta-4-released.8732/

Removal of Home Tab/Link
If you do not enter a home URL in the options, the "Home" tab and link in the bread crumb will no longer appear.

Multiple Navigation Tab Positions for Developers
Developers utilizing the navigation_tabs event can now choose the position where their new tab will appear.
Additionally, if a user does not enter a home URL, the first tab inserted into the "home" position will assume that duty.
 
Removal of Home Tab/Link
If you do not enter a home URL in the options, the "Home" tab and link in the bread crumb will no longer appear.

Multiple Navigation Tab Positions for Developers
Developers utilizing the navigation_tabs event can now choose the position where their new tab will appear.
Additionally, if a user does not enter a home URL, the first tab inserted into the "home" position will assume that duty.

Oh yea.

That did solve many problems, except it didn't change one key thing:
users going to www.mysite.com are directed to the FORUMs by default.
Not so great having a Home Page that people don't land on.

Of course the work around is installing xenforo to a subdirectory and using the re-direct.

So it's like a Home Tab that people don't land on :(
 
The framework supports programmatically replacing the homepage with your own route/controller/whatever setup; and moving the forum listing to, /forum/, for example. There were just two bugs which got in the way of doing this elegantly. Mike fixed them for the next release...
For testing purpose, I've set the recent activity page as default on my testbed: http://xf.geekpoint.net/
So far so good.

Once Beta 6 is released, I'll post the tutorial if needed. :)
 
That wasn't exactly a bug, in my opinion. Workarounds were possible, but they were nowhere near as elegant as what we can do now that these two issues are fixed.
 
That wasn't exactly a bug, in my opinion. Workarounds were possible, but they were nowhere near as elegant as what we can do now that these two issues are fixed.
Any chance we can get that guide earlier than later? I'm okay with doing file edits for now, until the bugs get fixed in the official release. The reason I ask is that I'm running my portal on a production site and I wont like it to be the index.
 
I look forward to that tutorial :)
This is exactly what I want to achieve but using a Page.
When I wrote it originally, I didn't have node pages in mind.
Had to change some bits to make the system more "generic". :)

Any chance we can get that guide earlier than later? I'm okay with doing file edits for now, until the bugs get fixed in the official release.
Here you go:
http://xenforo.com/community/threads/library-set-your-own-route-controller-as-homepage.10156/

The patches for XenForo_Link (beta 5) are provided in the 2nd post.
 
Top Bottom