Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 27 |
| LoginLogoutMenuLink | |
0.00% |
0 / 1 |
|
0.00% |
0 / 5 |
56 | |
0.00% |
0 / 27 |
| __construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| create | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 8 |
|||
| getTitle | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 7 |
|||
| getRouteName | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 7 |
|||
| getCacheContexts | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| <?php | |
| /** | |
| * @file | |
| * Contains \Drupal\user\Plugin\Menu\LoginLogoutMenuLink. | |
| */ | |
| 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; | |
| /** | |
| * A menu link that shows "Log in" or "Log out" as appropriate. | |
| */ | |
| class LoginLogoutMenuLink extends MenuLinkDefault { | |
| /** | |
| * The current user. | |
| * | |
| * @var \Drupal\Core\Session\AccountInterface | |
| */ | |
| protected $currentUser; | |
| /** | |
| * Constructs a new LoginLogoutMenuLink. | |
| * | |
| * @param array $configuration | |
| * A configuration array containing information about the plugin instance. | |
| * @param string $plugin_id | |
| * The plugin_id for the plugin instance. | |
| * @param mixed $plugin_definition | |
| * The plugin implementation definition. | |
| * @param \Drupal\Core\Menu\StaticMenuLinkOverridesInterface $static_override | |
| * The static override storage. | |
| * @param \Drupal\Core\Session\AccountInterface $current_user | |
| * The current user. | |
| */ | |
| 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; | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| 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') | |
| ); | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function getTitle() { | |
| if ($this->currentUser->isAuthenticated()) { | |
| return $this->t('Log out'); | |
| } | |
| else { | |
| return $this->t('Log in'); | |
| } | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function getRouteName() { | |
| if ($this->currentUser->isAuthenticated()) { | |
| return 'user.logout'; | |
| } | |
| else { | |
| return 'user.login'; | |
| } | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function getCacheContexts() { | |
| return ['user.roles:authenticated']; | |
| } | |
| } |