-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converted the user bar into a view helper.
- Loading branch information
Showing
3 changed files
with
74 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
namespace Omeka\View\Helper; | ||
|
||
use Zend\View\Helper\AbstractHelper; | ||
|
||
/** | ||
* View helper for rendering the user bar. | ||
*/ | ||
class UserBar extends AbstractHelper | ||
{ | ||
/** | ||
* The default partial view script. | ||
*/ | ||
const PARTIAL_NAME = 'common/user-bar'; | ||
|
||
/** | ||
* Render the user bar. | ||
* | ||
* @param string|null $partialName Name of view script, or a view model | ||
* @return string | ||
*/ | ||
public function __invoke($partialName = null) | ||
{ | ||
$view = $this->getView(); | ||
$showUserBar = $view->siteSetting('show_user_bar', 0); | ||
if ($showUserBar == -1) { | ||
return ''; | ||
} | ||
|
||
$user = $view->identity(); | ||
if ($showUserBar != 1 && !$user) { | ||
return ''; | ||
} | ||
|
||
$site = $view->vars()->site; | ||
if (empty($site)) { | ||
return ''; | ||
} | ||
|
||
$partialName = $partialName ?: self::PARTIAL_NAME; | ||
|
||
return $view->partial( | ||
$partialName, | ||
[ | ||
'site' => $site, | ||
'user' => $user, | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,26 @@ | ||
<?php | ||
$showUserBar = $this->siteSetting('show_user_bar', 0); | ||
$currentUser = $this->identity(); | ||
$escape = $this->plugin('escapeHtml'); | ||
$this->headLink()->prependStylesheet($this->assetUrl('css/user-bar.css', 'Omeka')); | ||
$this->headLink()->prependStylesheet('//fonts.googleapis.com/css?family=Source+Code+Pro|Lato:400,400italic,700,700italic'); | ||
?> | ||
<?php if ($showUserBar == 1 || ($showUserBar != -1 && $currentUser)): ?> | ||
<?php | ||
$escape = $this->plugin('escapeHtml'); | ||
$this->headLink()->prependStylesheet($this->assetUrl('css/user-bar.css', 'Omeka')); | ||
$this->headLink()->prependStylesheet('//fonts.googleapis.com/css?family=Source+Code+Pro|Lato:400,400italic,700,700italic'); | ||
<div id="user-bar"> | ||
<?php if ($user): ?> | ||
<?php if ($this->userIsAllowed('Omeka\Controller\Admin\Index', 'index')): ?> | ||
<div class="logo"><a href="<?php echo $this->url('admin'); ?>"><?php echo $this->setting('installation_title', 'Omeka S'); ?></a></div> | ||
<span class="current-site"> | ||
<a href="<?php echo $site->adminUrl('show'); ?>"><?php echo $site->title(); ?></a> | ||
</span> | ||
<?php endif; ?> | ||
<span class="user-id"> | ||
<?php | ||
echo sprintf($this->translate('Signed in as %s'), '<a href="' . $this->url('admin/id', [ | ||
'controller' => 'user', | ||
'id' => $user->getId(), | ||
]) . '">' . $escape($user->getName()) . '</a>'); | ||
?> | ||
<div id="user-bar"> | ||
<?php if ($currentUser): ?> | ||
<?php if ($this->userIsAllowed('Omeka\Controller\Admin\Index', 'index')): ?> | ||
<div class="logo"><a href="<?php echo $this->url('admin'); ?>"><?php echo $this->setting('installation_title', 'Omeka S'); ?></a></div> | ||
<span class="current-site"> | ||
<a href="<?php echo $site->adminUrl('show'); ?>"><?php echo $site->title(); ?></a> | ||
</span> | ||
<?php endif; ?> | ||
<span class="user-id"> | ||
<?php | ||
echo sprintf($this->translate('Signed in as %s'), '<a href="' . $this->url('admin/id', [ | ||
'controller' => 'user', | ||
'id' => $this->identity()->getId(), | ||
]) . '">' . $escape($this->identity()->getName()) . '</a>'); | ||
?> | ||
</span> | ||
<span class="logout"><a href="<?php echo $this->url('logout'); ?>"><?php echo $this->translate('Logout'); ?></a></span> | ||
<?php else: ?> | ||
<span class="login"><a href="<?php echo $this->url('login'); ?>"><?php echo $this->translate('Log in'); ?></a></span> | ||
<?php endif; ?> | ||
</div> | ||
<?php endif; ?> | ||
</span> | ||
<span class="logout"><a href="<?php echo $this->url('logout'); ?>"><?php echo $this->translate('Logout'); ?></a></span> | ||
<?php else: ?> | ||
<span class="login"><a href="<?php echo $this->url('login'); ?>"><?php echo $this->translate('Log in'); ?></a></span> | ||
<?php endif; ?> | ||
</div> |