Permalink
Browse files

feature(menus): elgg_register_title_button() can now check entity typ…

…e and subtype

This adds more granularity to elgg_register_title_button() allowing to check container
permissions for a specific entity type and subtype before registering a title menu item
  • Loading branch information...
hypeJunction committed Apr 6, 2016
1 parent d2e95b4 commit a0c118ad46f3038a027c1d56313b9369c5ec6ae8
View
@@ -204,33 +204,34 @@ function elgg_get_menu_item($menu_name, $item_name) {
*
* This is used primarily to support adding an add content button
*
* @param string $handler The handler to use or null to autodetect from context
* @param string $name Name of the button
* @param string $handler The handler to use or null to autodetect from context
* @param string $name Name of the button (defaults to 'add')
* @param string $entity_type Optional entity type to be added (used to verify canWriteToContainer permission)
* @param string $entity_subtype Optional entity subtype to be added (used to verify canWriteToContainer permission)
* @return void
* @since 1.8.0
*/
function elgg_register_title_button($handler = null, $name = 'add') {
if (elgg_is_logged_in()) {
if (!$handler) {
$handler = elgg_get_context();
}
function elgg_register_title_button($handler = null, $name = 'add', $entity_type = 'all', $entity_subtype = 'all') {
if (!$handler) {
$handler = elgg_get_context();
}
$owner = elgg_get_page_owner_entity();
if (!$owner) {
// no owns the page so this is probably an all site list page
$owner = elgg_get_logged_in_user_entity();
}
if ($owner && $owner->canWriteToContainer()) {
$guid = $owner->getGUID();
elgg_register_menu_item('title', array(
'name' => $name,
'href' => "$handler/$name/$guid",
'text' => elgg_echo("$handler:$name"),
'link_class' => 'elgg-button elgg-button-action',
));
}
$owner = elgg_get_page_owner_entity();
if (!$owner) {
// noone owns the page so this is probably an all site list page
$owner = elgg_get_logged_in_user_entity();
}
if (!$owner || !$owner->canWriteToContainer(0, $entity_type, $entity_subtype)) {
return;
}
elgg_register_menu_item('title', array(
'name' => $name,
'href' => "$handler/$name/$owner->guid",
'text' => elgg_echo("$handler:$name"),
'link_class' => 'elgg-button elgg-button-action',
));
}
/**
View
@@ -59,7 +59,7 @@ function blog_get_page_content_list($container_guid = NULL) {
elgg_push_breadcrumb(elgg_echo('blog:blogs'));
}
elgg_register_title_button();
elgg_register_title_button('blog', 'add', 'object', 'blog');
$return['content'] = elgg_list_entities($options);
@@ -17,7 +17,7 @@
elgg_push_breadcrumb($crumbs_title, "blog/owner/{$user->username}");
elgg_push_breadcrumb(elgg_echo('friends'));
elgg_register_title_button();
elgg_register_title_button('blog', 'add', 'object', 'blog');
$options = [
'type' => 'object',
@@ -8,7 +8,7 @@
elgg_pop_breadcrumb();
elgg_push_breadcrumb(elgg_echo('bookmarks'));
elgg_register_title_button();
elgg_register_title_button('bookmarks', 'add', 'object', 'bookmarks');
$content = elgg_list_entities(array(
'type' => 'object',
@@ -13,7 +13,7 @@
elgg_push_breadcrumb($page_owner->name, "bookmarks/owner/$page_owner->username");
elgg_push_breadcrumb(elgg_echo('friends'));
elgg_register_title_button();
elgg_register_title_button('bookmarks', 'add', 'object', 'bookmarks');
$title = elgg_echo('bookmarks:friends');
@@ -13,7 +13,7 @@
elgg_push_breadcrumb($page_owner->name);
elgg_register_title_button();
elgg_register_title_button('bookmarks', 'add', 'object', 'bookmarks');
$options = [
'type' => 'object',
@@ -15,7 +15,7 @@
elgg_push_breadcrumb($group->name, $group->getURL());
elgg_push_breadcrumb(elgg_echo('item:object:discussion'));
elgg_register_title_button();
elgg_register_title_button('discussion', 'add', 'object', 'discussion');
$title = elgg_echo('item:object:discussion');
@@ -17,7 +17,7 @@
elgg_push_breadcrumb(elgg_echo('item:object:discussion'));
elgg_register_title_button();
elgg_register_title_button('discussion', 'add', 'object', 'discussion');
$title = elgg_echo('item:object:discussion');
@@ -14,7 +14,7 @@
elgg_push_breadcrumb($owner->name, "file/owner/$owner->username");
elgg_push_breadcrumb(elgg_echo('friends'));
elgg_register_title_button();
elgg_register_title_button('file', 'add', 'object', 'file');
$title = elgg_echo("file:friends");
@@ -16,7 +16,7 @@
elgg_push_breadcrumb(elgg_echo('file'), "file/all");
elgg_push_breadcrumb($owner->name);
elgg_register_title_button();
elgg_register_title_button('file', 'add', 'object', 'file');
$params = array();
@@ -17,7 +17,7 @@
$owner = elgg_get_page_owner_entity();
elgg_group_gatekeeper();
elgg_register_title_button();
elgg_register_title_button('file', 'add', 'object', 'file');
// Get input
$md_type = 'simpletype';
@@ -7,7 +7,7 @@
elgg_push_breadcrumb(elgg_echo('file'));
elgg_register_title_button();
elgg_register_title_button('file', 'add', 'object', 'file');
$title = elgg_echo('file:all');
@@ -5,7 +5,7 @@
elgg_push_breadcrumb(elgg_echo('groups'));
if (elgg_get_plugin_setting('limited_groups', 'groups') != 'yes' || elgg_is_admin_logged_in()) {
elgg_register_title_button();
elgg_register_title_button('groups', 'add', 'group');
}
$selected_tab = get_input('filter', 'newest');
@@ -19,7 +19,7 @@
elgg_push_breadcrumb($title);
if (elgg_get_plugin_setting('limited_groups', 'groups') != 'yes' || elgg_is_admin_logged_in()) {
elgg_register_title_button();
elgg_register_title_button('groups', 'add', 'group');
}
$dbprefix = elgg_get_config('dbprefix');
@@ -10,7 +10,7 @@
elgg_push_breadcrumb($title);
if (elgg_get_plugin_setting('limited_groups', 'groups') != 'yes' || elgg_is_admin_logged_in()) {
elgg_register_title_button();
elgg_register_title_button('groups', 'add', 'group');
}
$dbprefix = elgg_get_config('dbprefix');
@@ -25,7 +25,7 @@
elgg_push_breadcrumb(elgg_echo('messages:inbox'));
elgg_register_title_button();
elgg_register_title_button('messages', 'add', 'object', 'messages');
$title = elgg_echo('messages:user', array($page_owner->name));
@@ -27,7 +27,7 @@
elgg_push_breadcrumb(elgg_echo('messages:sent'));
elgg_register_title_button();
elgg_register_title_button('messages', 'add', 'object', 'messages');
$title = elgg_echo('messages:sentmessages', array($page_owner->name));
@@ -13,7 +13,7 @@
elgg_push_breadcrumb($owner->name, "pages/owner/$owner->username");
elgg_push_breadcrumb(elgg_echo('friends'));
elgg_register_title_button();
elgg_register_title_button('pages', 'add', 'object', 'page_top');
$title = elgg_echo('pages:friends');
@@ -17,7 +17,7 @@
elgg_push_breadcrumb($owner->name);
elgg_register_title_button();
elgg_register_title_button('pages', 'add', 'object', 'page_top');
$content = elgg_list_entities(array(
'type' => 'object',
@@ -10,7 +10,7 @@
elgg_pop_breadcrumb();
elgg_push_breadcrumb(elgg_echo('pages'));
elgg_register_title_button();
elgg_register_title_button('pages', 'add', 'object', 'page_top');
$content = elgg_list_entities(array(
'type' => 'object',
@@ -6,10 +6,22 @@
* @subpackage Social.Collections
*/
$owner = elgg_get_logged_in_user_entity();
if (!$owner) {
forward('', '404');
}
$title = elgg_echo('friends:collections');
elgg_register_title_button('collections', 'add');
if ($owner->canEdit()) {
elgg_register_menu_item('title', [
'name' => 'add',
'href' => "collections/add/$owner->guid",
'text' => elgg_echo('collections:add'),
'link_class' => 'elgg-button elgg-button-action',
]);
}
$content = elgg_view_access_collections(elgg_get_logged_in_user_guid());
$content = elgg_view_access_collections($owner->guid);
$body = elgg_view_layout('content', array(
'filter' => false,

0 comments on commit a0c118a

Please sign in to comment.