Skip to content

Commit

Permalink
fix(navigation): correct container set on title menu button
Browse files Browse the repository at this point in the history
When viewing another users content listing page the title menu button
'add content' could point to the wrong container, namely the listed user
instead of the current logged in user.
Now the button points to the current logged in user

fixes: #10846
  • Loading branch information
jeabakker committed Dec 7, 2017
1 parent 61c1ea6 commit 77c8f00
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions engine/lib/navigation.php
Expand Up @@ -234,10 +234,22 @@ function elgg_register_title_button($handler = null, $name = 'add', $entity_type
// noone owns the page so this is probably an all site list page
$owner = elgg_get_logged_in_user_entity();
}

if (($name === 'add') && ($owner instanceof ElggUser)) {
// make sure the add link goes to the current logged in user, not the page owner
$logged_in_user = elgg_get_logged_in_user_entity();
if (!empty($logged_in_user) && ($logged_in_user->guid !== $owner->guid)) {
// change the 'owner' for the link to the current logged in user
$owner = $logged_in_user;
}
}

// do we have an owner and is the current user allowed to create content here
if (!$owner || !$owner->canWriteToContainer(0, $entity_type, $entity_subtype)) {
return;
}

// register the title menu item
elgg_register_menu_item('title', [
'name' => $name,
'href' => "$handler/$name/$owner->guid",
Expand Down

0 comments on commit 77c8f00

Please sign in to comment.