LoginLogoutMenuLink.php in Zircon Profile 8
File
core/modules/user/src/Plugin/Menu/LoginLogoutMenuLink.php
View source
<?php
namespace Drupal\user\Plugin\Menu;
use Drupal\Core\Menu\MenuLinkDefault;
use Drupal\Core\Menu\StaticMenuLinkOverridesInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class LoginLogoutMenuLink extends MenuLinkDefault {
protected $currentUser;
public function __construct(array $configuration, $plugin_id, $plugin_definition, StaticMenuLinkOverridesInterface $static_override, AccountInterface $current_user) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $static_override);
$this->currentUser = $current_user;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('menu_link.static.overrides'), $container
->get('current_user'));
}
public function getTitle() {
if ($this->currentUser
->isAuthenticated()) {
return $this
->t('Log out');
}
else {
return $this
->t('Log in');
}
}
public function getRouteName() {
if ($this->currentUser
->isAuthenticated()) {
return 'user.logout';
}
else {
return 'user.login';
}
}
public function getCacheContexts() {
return [
'user.roles:authenticated',
];
}
}