- // Add logout & user account links or login link.
- $links_cache_contexts = [];
- if ($user->isAuthenticated()) {
- $links = [
- 'account' => [
- 'title' => t('View profile'),
- 'url' => Url::fromRoute('user.page'),
- 'attributes' => [
- 'title' => t('User account'),
- ],
- ],
- 'account_edit' => [
- 'title' => t('Edit profile'),
- 'url' => Url::fromRoute('entity.user.edit_form', ['user' => $user->id()]),
- 'attributes' => [
- 'title' => t('Edit user account'),
- ],
- ],
- 'logout' => [
- 'title' => t('Log out'),
- 'url' => Url::fromRoute('user.logout'),
- ],
- ];
- // The "Edit user account" link is per-user.
- $links_cache_contexts[] = 'user';
- }
- else {
- $links = [
- 'login' => [
- 'title' => t('Log in'),
- 'url' => Url::fromRoute('user.page'),
- ],
- ];
- }
-