Skip to content

Commit

Permalink
Converted the user bar into a view helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-KM committed Oct 22, 2017
1 parent 8d0dc86 commit fbfb163
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 29 deletions.
1 change: 1 addition & 0 deletions application/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@
'themeSettingAssetUrl' => View\Helper\ThemeSettingAssetUrl::class,
'formColorPicker' => Form\View\Helper\FormColorPicker::class,
'thumbnail' => View\Helper\Thumbnail::class,
'userBar' => View\Helper\UserBar::class,
],
'factories' => [
'api' => Service\ViewHelper\ApiFactory::class,
Expand Down
50 changes: 50 additions & 0 deletions application/src/View/Helper/UserBar.php
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,
]
);
}
}
52 changes: 23 additions & 29 deletions application/view/common/user-bar.phtml
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>

0 comments on commit fbfb163

Please sign in to comment.