Skip to content

Commit

Permalink
Added check permission to menu link
Browse files Browse the repository at this point in the history
  • Loading branch information
vcsvinicius authored and ronaldtebrake committed Mar 25, 2024
1 parent 2946a1a commit de61d82
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ function social_activity_social_user_account_header_account_links(array $context
],
];

$link = Link::createFromRoute($title_link, 'view.activity_stream_notifications.page_1');

return [
'notification_mobile' => [
'#wrapper_attributes' => [
Expand All @@ -151,7 +153,8 @@ function social_activity_social_user_account_header_account_links(array $context
'#attributes' => [
'title' => new TranslatableMarkup('Notification Center'),
],
] + Link::createFromRoute($title_link, 'view.activity_stream_notifications.page_1')->toRenderable(),
'#access' => $link->getUrl()->access(),
] + $link->toRenderable(),
];
}

Expand Down
13 changes: 8 additions & 5 deletions modules/social_features/social_album/social_album.module
Original file line number Diff line number Diff line change
Expand Up @@ -537,18 +537,21 @@ function social_album_social_user_account_header_account_links(array $context) {
return [];
}

$link = Link::createFromRoute(
(new TranslatableMarkup('My albums')),
'view.albums.page_albums_overview',
['user' => $context['user']->id()]
);

return [
'my_albums' => [
'#type' => 'link',
'#attributes' => [
'title' => new TranslatableMarkup('View my albums'),
],
'#weight' => 550,
] + Link::createFromRoute(
(new TranslatableMarkup('My albums')),
'view.albums.page_albums_overview',
['user' => $context['user']->id()]
)->toRenderable(),
'#access' => $link->getUrl()->access(),
] + $link->toRenderable(),
];
}

Expand Down
7 changes: 6 additions & 1 deletion modules/social_features/social_book/social_book.module
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ function social_book_menu_local_tasks_alter(&$data, $route_name) {
* allowed to create new books.
*/
function social_book_social_user_account_header_create_links($context): array {
$link = Link::createFromRoute((new TranslatableMarkup('New Book Page')), 'node.add', [
'node_type' => 'book',
]);

return [
'add_book' => [
'#type' => 'link',
'#attributes' => [
'title' => new TranslatableMarkup('Create New Book Page'),
],
] + Link::createFromRoute((new TranslatableMarkup('New Book Page')), 'node.add', ['node_type' => 'book'])->toRenderable(),
'#access' => $link->getUrl()->access(),
] + $link->toRenderable(),
];
}

Expand Down
6 changes: 4 additions & 2 deletions modules/social_features/social_core/social_core.module
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ function social_core_social_user_account_header_account_links(array $context) {
];
}

$link = Link::createFromRoute($title, 'social_core.my_invites');

return [
'divider_no_mobile' => [
'#wrapper_attributes' => [
Expand All @@ -240,8 +242,8 @@ function social_core_social_user_account_header_account_links(array $context) {
'title' => new TranslatableMarkup('Invites'),
],
'#weight' => 350,
] + Link::createFromRoute($title, 'social_core.my_invites')->toRenderable(),

'#access' => $link->getUrl()->access(),
] + $link->toRenderable(),
];
}
}
Expand Down
16 changes: 12 additions & 4 deletions modules/social_features/social_event/social_event.module
Original file line number Diff line number Diff line change
Expand Up @@ -666,14 +666,19 @@ function _social_event_user_timezone($timezone) {
* Adds the "Create Event" link to the content creation menu.
*/
function social_event_social_user_account_header_create_links($context) {
$link = Link::createFromRoute((new TranslatableMarkup('New Event')), 'node.add', [
'node_type' => 'event',
]);

return [
'add_event' => [
'#type' => 'link',
'#attributes' => [
'title' => new TranslatableMarkup('Create New Event'),
],
'#weight' => 100,
] + Link::createFromRoute((new TranslatableMarkup('New Event')), 'node.add', ['node_type' => 'event'])->toRenderable(),
'#access' => $link->getUrl()->access(),
] + $link->toRenderable(),
];
}

Expand All @@ -688,16 +693,19 @@ function social_event_social_user_account_header_account_links(array $context) {
return [];
}

$link = Link::createFromRoute((new TranslatableMarkup('My events')), 'view.events.events_overview', [
'user' => $context['user']->id(),
]);

return [
'my_events' => [
'#type' => 'link',
'#attributes' => [
'title' => new TranslatableMarkup('View my events'),
],
'#weight' => 600,
] + Link::createFromRoute((new TranslatableMarkup('My events')), 'view.events.events_overview', [
'user' => $context['user']->id(),
])->toRenderable(),
'#access' => $link->getUrl()->access(),
] + $link->toRenderable(),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,17 @@ function social_follow_content_event_enrollment_follow(EntityInterface $entity)
* Adds the "Following" link to the user menu.
*/
function social_follow_content_social_user_account_header_account_links(array $context) {
$link = Link::createFromRoute((new TranslatableMarkup('Following')), 'view.following.following');

return [
'my_content' => [
'#type' => 'link',
'#attributes' => [
'title' => new TranslatableMarkup("View content I'm following"),
],
'#weight' => 1000,
] + Link::createFromRoute((new TranslatableMarkup('Following')), 'view.following.following')->toRenderable(),
'#access' => $link->getUrl()->access(),
] + $link->toRenderable(),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ function social_follow_taxonomy_theme($existing, $type, $theme, $path) {
* Adds the "Following tags" link to the user menu.
*/
function social_follow_taxonomy_social_user_account_header_account_links(array $context) {
$link = Link::createFromRoute((new TranslatableMarkup('Following tags')), 'view.following_tags.following_tags');

return [
'my_tags' => [
'#type' => 'link',
'#attributes' => [
'title' => new TranslatableMarkup("View tags I'm following"),
],
'#weight' => 1001,
] + Link::createFromRoute((new TranslatableMarkup('Following tags')), 'view.following_tags.following_tags')->toRenderable(),
'#access' => $link->getUrl()->access(),
] + $link->toRenderable(),
];
}

Expand Down
10 changes: 7 additions & 3 deletions modules/social_features/social_group/social_group.module
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,7 @@ function social_group_social_user_account_header_create_links($context) {
'title' => new TranslatableMarkup('Create New Group'),
],
'#weight' => 500,
'#access' => $route_add_group->getUrl()->access(),
] + $route_add_group->toRenderable(),
];
}
Expand Down Expand Up @@ -2288,16 +2289,19 @@ function social_group_social_user_account_header_account_links(array $context) {
return [];
}

$link = Link::createFromRoute((new TranslatableMarkup('My groups')), 'view.groups.page_user_groups', [
'user' => $context['user']->id(),
]);

return [
'my_groups' => [
'#type' => 'link',
'#attributes' => [
'title' => new TranslatableMarkup('View my groups'),
],
'#weight' => 800,
] + Link::createFromRoute((new TranslatableMarkup('My groups')), 'view.groups.page_user_groups', [
'user' => $context['user']->id(),
])->toRenderable(),
'#access' => $link->getUrl()->access(),
] + $link->toRenderable(),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,16 +356,19 @@ function social_landing_page_social_tagging_type_alter(array &$items): void {
* Adds the "Create Landing Page" link to the content creation menu.
*/
function social_landing_page_social_user_account_header_create_links($context) {
$link = Link::createFromRoute((new TranslatableMarkup('New Landing Page')), 'node.add', [
'node_type' => 'landing_page',
]);

return [
'add_landing_page' => [
'#type' => 'link',
'#attributes' => [
'title' => new TranslatableMarkup('Create New Landing Page'),
],
'#weight' => 400,
] + Link::createFromRoute((new TranslatableMarkup('New Landing Page')), 'node.add', [
'node_type' => 'landing_page',
])->toRenderable(),
'#access' => $link->getUrl()->access(),
] + $link->toRenderable(),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,8 @@ function social_private_message_social_user_account_header_account_links(array $
],
];

$link = Link::createFromRoute($title_link, 'social_private_message.inbox');

return [
'messages_mobile' => [
'#type' => 'link',
Expand All @@ -552,7 +554,8 @@ function social_private_message_social_user_account_header_account_links(array $
'#attributes' => [
'title' => new TranslatableMarkup('Inbox'),
],
] + Link::createFromRoute($title_link, 'social_private_message.inbox')->toRenderable(),
'#access' => $link->getUrl()->access(),
] + $link->toRenderable(),
];

}
Expand Down
15 changes: 10 additions & 5 deletions modules/social_features/social_profile/social_profile.module
Original file line number Diff line number Diff line change
Expand Up @@ -841,24 +841,29 @@ function social_profile_social_user_account_header_account_links(array $context)
return [];
}

$my_profile_link = Link::createFromRoute((new TranslatableMarkup('My profile')), 'user.page');
$edit_profile_link = Link::createFromRoute((new TranslatableMarkup('Edit profile')), 'profile.user_page.single', [
'user' => $context['user']->id(),
'profile_type' => 'profile',
]);

return [
'my_profile' => [
'#type' => 'link',
'#attributes' => [
'title' => new TranslatableMarkup('View my profile'),
],
'#weight' => 500,
] + Link::createFromRoute((new TranslatableMarkup('My profile')), 'user.page')->toRenderable(),
'#access' => $my_profile_link->getUrl()->access(),
] + $my_profile_link->toRenderable(),
'edit_profile' => [
'#type' => 'link',
'#attributes' => [
'title' => new TranslatableMarkup("Edit profile"),
],
'#weight' => 1300,
] + Link::createFromRoute((new TranslatableMarkup('Edit profile')), 'profile.user_page.single', [
'user' => $context['user']->id(),
'profile_type' => 'profile',
])->toRenderable(),
'#access' => $edit_profile_link->getUrl()->access(),
] + $edit_profile_link->toRenderable(),
];
}

Expand Down
16 changes: 12 additions & 4 deletions modules/social_features/social_topic/social_topic.module
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,19 @@ function social_topic_social_tagging_type_alter(array &$items): void {
* Adds the "Create Topic" link to the content creation menu.
*/
function social_topic_social_user_account_header_create_links($context) {
$link = Link::createFromRoute((new TranslatableMarkup('New Topic')), 'node.add', [
'node_type' => 'topic',
]);

return [
'add_topic' => [
'#type' => 'link',
'#attributes' => [
'title' => new TranslatableMarkup('Create New Topic'),
],
'#weight' => 200,
] + Link::createFromRoute((new TranslatableMarkup('New Topic')), 'node.add', ['node_type' => 'topic'])->toRenderable(),
'#access' => $link->getUrl()->access(),
] + $link->toRenderable(),
];
}

Expand All @@ -235,16 +240,19 @@ function social_topic_social_user_account_header_account_links(array $context) {
return [];
}

$link = Link::createFromRoute((new TranslatableMarkup('My topics')), 'view.topics.page_profile', [
'user' => $context['user']->id(),
]);

return [
'my_topics' => [
'#type' => 'link',
'#attributes' => [
'title' => new TranslatableMarkup('View my topics'),
],
'#weight' => 700,
] + Link::createFromRoute((new TranslatableMarkup('My topics')), 'view.topics.page_profile', [
'user' => $context['user']->id(),
])->toRenderable(),
'#access' => $link->getUrl()->access(),
] + $link->toRenderable(),
];
}

Expand Down
13 changes: 9 additions & 4 deletions modules/social_features/social_user/social_user.module
Original file line number Diff line number Diff line change
Expand Up @@ -484,16 +484,20 @@ function social_user_social_user_account_header_account_links(array $context) {
return [];
}

$my_account_link = Link::createFromRoute((new TranslatableMarkup('Settings')), 'entity.user.edit_form', [
'user' => $context['user']->id(),
]);
$logout_link = Link::createFromRoute((new TranslatableMarkup('Logout')), 'user.logout');

return [
'my_account' => [
'#type' => 'link',
'#attributes' => [
'title' => new TranslatableMarkup("Settings"),
],
'#weight' => 1200,
] + Link::createFromRoute((new TranslatableMarkup('Settings')), 'entity.user.edit_form', [
'user' => $context['user']->id(),
])->toRenderable(),
'#access' => $my_account_link->getUrl()->access(),
] + $my_account_link->toRenderable(),
'divider_logout' => [
"#wrapper_attributes" => [
"class" => ["divider"],
Expand All @@ -507,7 +511,8 @@ function social_user_social_user_account_header_account_links(array $context) {
'title' => new TranslatableMarkup("Logout"),
],
'#weight' => 1500,
] + Link::createFromRoute((new TranslatableMarkup('Logout')), 'user.logout')->toRenderable(),
'#access' => $logout_link->getUrl()->access(),
] + $logout_link->toRenderable(),
];
}

Expand Down

0 comments on commit de61d82

Please sign in to comment.