LoginLogoutMenuLink.php in SAML Authentication 8.2
File
src/Plugin/Menu/LoginLogoutMenuLink.php
View source
<?php
namespace Drupal\samlauth\Plugin\Menu;
use Drupal\Core\Menu\StaticMenuLinkOverridesInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\user\Plugin\Menu\LoginLogoutMenuLink as DrupalLoginLogoutMenuLink;
use Symfony\Component\DependencyInjection\ContainerInterface;
class LoginLogoutMenuLink extends DrupalLoginLogoutMenuLink {
protected $config;
public function __construct(array $configuration, $plugin_id, $plugin_definition, StaticMenuLinkOverridesInterface $static_override, AccountInterface $current_user, ConfigFactoryInterface $config_factory) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $static_override, $current_user);
$this->config = $config_factory
->get('samlauth.authentication');
}
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'), $container
->get('config.factory'));
}
public function getTitle() {
if ($this->currentUser
->isAuthenticated()) {
$setting = 'logout_menu_item_title';
}
else {
$setting = 'login_menu_item_title';
}
$title = $this->config
->get($setting);
return $title ?: parent::getTitle();
}
public function getRouteName() {
if ($this->currentUser
->isAuthenticated()) {
return 'samlauth.saml_controller_logout';
}
else {
return 'samlauth.saml_controller_login';
}
}
}