Help with Login in Nav Menu

Hi all,
I recently added a login form to the navbar by “porting” lines from the userblock plugin.

Everything seems to work fine (I can login, and logout) with all the journals currently available and setup.
Problem starts when I create a new journal and try to go to the journal page or it’s setups page.

The page suddenly breaks at the navbar. if I comment out the {if $userSession->getSessionVar('signedInAs')} statement in this “modified” navbar, everything works fine, except that the {translate} lines also don’t translate. everything comes out looking ####-ish (a locale problem). But once I comment out the line above and succeed in finishing step5 of the journal setup, everything continues working again (even if I return the “problem line”).

the plugin in the navbar is obviosly the issue, but I can’t figure it out (and I REALLY need a login form there that has those beautiful options that come with the userblock plugin) :cry:.

Please guys how do I do this?
any help will be appreciated.


I suspect that your cut and paste only worked because you kept the login block plugin at the side bar right?

You can’t just copy template code and expects it to work everywhere. The $userSession variable, for example, it’s assigned to the template manager (the object that manage all the template rendering, etc) in the UserBlockPlugin. When you try to use that variable without any plugin assigning it to the template manager, then you have the error.

I am not sure why you saw this problem just in the journal creation page and the setup ones. But I bet it’s because the UserBlockPlugin is not having a chance to add the variables it needs before you try to use those variables in the menu.

I would recommend you to take a look at the UserBlockPlugin::getContents() method and move that code also to a place where you make sure it will be executed for every request, like the TemplateManager::display() method.

The missing translation is also because the proper locale file is not loaded for that key, you should load the LOCALE_COMPONENT_PKP_USER. Again, you can do that in the display method I said before, if you want to show the login form inside the navbar.


1 Like

thanks @beghelli,
I’ll do what you suggested, and give feedback on the results. I already have a good feeling it’ll solve the problem. thanks for the prompt reply.
I haven’t been online since, as I was having issues with my computer.

Hi @beghelli,
I did as you suggested, and I’m back with the results.

I found the TemplateManager class, but didn’t find the display method you suggested.
It turned out, TemplateManager was extending PKPTemplateManager, so I found the display method in PKPTemplateManager, and “dumped” the following lines in it(just before $output is initialised to null, that is $output = null;).


	if (!defined('SESSION_DISABLE_INIT')) {
		$session =& Request::getSession();
		$this->assign_by_ref('userSession', $session);
		$this->assign('loggedInUsername', $session->getSessionVar('username'));
		$loginUrl = Request::url(null, 'login', 'signIn');
		if (Config::getVar('security', 'force_login_ssl')) {
			$loginUrl = String::regexp_replace('/^http:/', 'https:', $loginUrl);
		$this->assign('userBlockLoginUrl', $loginUrl);

Result: Magically, the “crashing navbar” at setup, is no more! :slight_smile: thanx to you @beghelli.
The locale ####-ish problem however, still persists. My guess is I’m doing the “LOCALE_COMPONENT_PKP_USER” thingy wrong.

please how do I do this right?
Thank you.

Try AppLocale::requireComponents(LOCALE_COMPONENT_PKP_USER); instead.

Thanks @ctgraham.
I tried what you suggested, but it still didn’t fix the problem.
At journal setup(step 5) though, if I include the userBlockPlugin in the sidebar, the problem disappears.
If I remove it (like I’d want to), the problem comes back.

Is there another method into which I could try the AppLocale::requireComponents(LOCALE_COMPONENT_PKP_USER); line, other than the display method? maybe that might work.