class DynamicMenuLinkMock
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Menu/DynamicMenuLinkMock.php \Drupal\Tests\Core\Menu\DynamicMenuLinkMock
- 8.9.x core/tests/Drupal/Tests/Core/Menu/DynamicMenuLinkMock.php \Drupal\Tests\Core\Menu\DynamicMenuLinkMock
- 11.x core/tests/Drupal/Tests/Core/Menu/DynamicMenuLinkMock.php \Drupal\Tests\Core\Menu\DynamicMenuLinkMock
Defines a mock implementation of a dynamic menu link used in tests only.
Has a dynamic route and title. This is rather contrived, but there are valid use cases.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
- class \Drupal\Core\Menu\MenuLinkBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\Core\Menu\MenuLinkInterface
- class \Drupal\Tests\Core\Menu\MenuLinkMock extends \Drupal\Core\Menu\MenuLinkBase
- class \Drupal\Tests\Core\Menu\DynamicMenuLinkMock extends \Drupal\Tests\Core\Menu\MenuLinkMock
- class \Drupal\Tests\Core\Menu\MenuLinkMock extends \Drupal\Core\Menu\MenuLinkBase
- class \Drupal\Core\Menu\MenuLinkBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\Core\Menu\MenuLinkInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
Expanded class hierarchy of DynamicMenuLinkMock
See also
\Drupal\user\Plugin\Menu\LoginLogoutMenuLink
File
-
core/
tests/ Drupal/ Tests/ Core/ Menu/ DynamicMenuLinkMock.php, line 17
Namespace
Drupal\Tests\Core\MenuView source
class DynamicMenuLinkMock extends MenuLinkMock {
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* Sets the current user.
*
* Allows the menu link to return the right title and route.
*
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
*
* @return $this
*/
public function setCurrentUser(AccountInterface $current_user) {
$this->currentUser = $current_user;
return $this;
}
/**
* {@inheritdoc}
*/
public function getTitle() {
if ($this->currentUser
->isAuthenticated()) {
return 'Log out';
}
else {
return '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',
];
}
}
Members
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.