Skip to content

Commit

Permalink
Widgetized the user menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
derekisbusy committed Feb 4, 2017
1 parent 7fe5766 commit 16ef9b3
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 48 deletions.
82 changes: 34 additions & 48 deletions views/settings/_menu.php
Original file line number Diff line number Diff line change
@@ -1,48 +1,34 @@
<?php

/*
* This file is part of the Dektrium project.
*
* (c) Dektrium project <http://github.com/dektrium>
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

use yii\helpers\Html;
use yii\widgets\Menu;

/**
* @var dektrium\user\models\User $user
*/

$user = Yii::$app->user->identity;
$networksVisible = count(Yii::$app->authClientCollection->clients) > 0;
?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
<?= Html::img($user->profile->getAvatarUrl(24), [
'class' => 'img-rounded',
'alt' => $user->username,
]) ?>
<?= $user->username ?>
</h3>
</div>
<div class="panel-body">
<?= Menu::widget([
'options' => [
'class' => 'nav nav-pills nav-stacked',
],
'items' => [
['label' => Yii::t('user', 'Profile'), 'url' => ['/user/settings/profile']],
['label' => Yii::t('user', 'Account'), 'url' => ['/user/settings/account']],
[
'label' => Yii::t('user', 'Networks'),
'url' => ['/user/settings/networks'],
'visible' => $networksVisible
],
],
]) ?>
</div>
</div>
<?php

/*
* This file is part of the Dektrium project.
*
* (c) Dektrium project <http://github.com/dektrium>
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

use yii\helpers\Html;
use dektrium\user\widgets\UserMenu;

/**
* @var dektrium\user\models\User $user
*/

$user = Yii::$app->user->identity;
?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
<?= Html::img($user->profile->getAvatarUrl(24), [
'class' => 'img-rounded',
'alt' => $user->username,
]) ?>
<?= $user->username ?>
</h3>
</div>
<div class="panel-body">
<?= UserMenu::widget() ?>
</div>
</div>
56 changes: 56 additions & 0 deletions widgets/UserMenu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/*
* This file is part of the Dektrium project.
*
* (c) Dektrium project <http://github.com/dektrium>
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

namespace dektrium\user\widgets;

use yii\widgets\Menu;
use Yii;
use yii\base\Widget;

/**
* User menu widget.
*/
class UserMenu extends Widget
{

/** @array \dektrium\user\models\RegistrationForm */
public $items;

public function init()
{
parent::init();

$networksVisible = count(Yii::$app->authClientCollection->clients) > 0;

$this->items = [
['label' => Yii::t('user', 'Profile'), 'url' => ['/user/settings/profile']],
['label' => Yii::t('user', 'Account'), 'url' => ['/user/settings/account']],
[
'label' => Yii::t('user', 'Networks'),
'url' => ['/user/settings/networks'],
'visible' => $networksVisible
],
];
}

/**
* @inheritdoc
*/
public function run()
{
return Menu::widget([
'options' => [
'class' => 'nav nav-pills nav-stacked',
],
'items' => $this->items,
]);
}
}

0 comments on commit 16ef9b3

Please sign in to comment.