Skip to content

Commit

Permalink
Add links to the primary nav to log in/out
Browse files Browse the repository at this point in the history
  • Loading branch information
mfairchild365 committed Mar 13, 2014
1 parent 0a7535d commit 78cd50c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Listener.php
Expand Up @@ -2,10 +2,13 @@

namespace SiteMaster\Plugins\Auth_unl;

use SiteMaster\Core\Config;
use SiteMaster\Core\Events\GetAuthenticationPlugins;
use SiteMaster\Core\Events\Navigation\MainCompile;
use SiteMaster\Core\Events\RoutesCompile;
use SiteMaster\Core\Events\User\Search;
use SiteMaster\Core\Plugin\PluginListener;
use SiteMaster\Core\User\Session;

class Listener extends PluginListener
{
Expand Down Expand Up @@ -82,4 +85,18 @@ protected function getSearchResultsForUID($term)

return array($json);
}

/**
* Compile primary navigation
*
* @param MainCompile $event
*/
public function onNavigationMainCompile(MainCompile $event)
{
if (Session::getCurrentUser()) {
$event->addNavigationItem(Config::get('URL') . 'auth/unl/logout/', 'Logout');
} else {
$event->addNavigationItem(Config::get('URL') . 'auth/unl/', 'Login');
}
}
}
7 changes: 7 additions & 0 deletions src/Plugin.php
Expand Up @@ -3,6 +3,7 @@

use SiteMaster\Core\Config;
use SiteMaster\Core\Events\GetAuthenticationPlugins;
use SiteMaster\Core\Events\Navigation\MainCompile;
use SiteMaster\Core\Events\RoutesCompile;
use SiteMaster\Core\Events\User\Search;
use SiteMaster\Core\Plugin\AuthenticationInterface;
Expand Down Expand Up @@ -93,6 +94,12 @@ function getEventListeners()
'listener' => array($listener, 'onUserSearch')
);

$listeners[] = array(
'event' => MainCompile::EVENT_NAME,
'listener' => array($listener, 'onNavigationMainCompile'),
'priority' => -6, //Should be the last primary nav element
);

return $listeners;
}

Expand Down

0 comments on commit 78cd50c

Please sign in to comment.