Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert the user bar into a helper #1108

Merged
merged 3 commits into from
Jul 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 8 additions & 4 deletions application/src/Form/SiteSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,17 @@ public function init()
]);
$this->add([
'name' => 'show_user_bar',
'type' => 'checkbox',
'type' => 'radio',
'options' => [
'label' => 'Always show user bar on public views', // @translate
'label' => 'Show user bar on public views', // @translate
'value_options' => [
'-1' => 'Never', // @translate
'0' => 'When identified', // @translate
'1' => 'Always', // @translate
],
],
'attributes' => [
'id' => 'show_user_bar',
'value' => $settings->get('show_user_bar', false),
'value' => $settings->get('show_user_bar', '0'),
],
]);
$this->add([
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,
]
);
}
}
54 changes: 25 additions & 29 deletions application/view/common/user-bar.phtml
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
<?php
$alwaysShowUserBar = $this->siteSetting('show_user_bar', false);
$currentUser = $this->identity();
<?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');
if (!isset($user)) $user = $this->identity();
?>

<?php if ( $currentUser || $alwaysShowUserBar): ?>
<?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): ?>
<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>
<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>