From 3c34ddf59804767e6a7deea3e3ee6c81d4a09601 Mon Sep 17 00:00:00 2001 From: cash Date: Sun, 26 Jun 2011 15:13:50 -0400 Subject: removed buttons logic from content header view, created convenience function rather than copying and pasting, and updated the blog plugin --- engine/lib/navigation.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'engine/lib/navigation.php') diff --git a/engine/lib/navigation.php b/engine/lib/navigation.php index 4b2c998a2..1cb289654 100644 --- a/engine/lib/navigation.php +++ b/engine/lib/navigation.php @@ -153,6 +153,41 @@ function elgg_is_menu_item_registered($menu_name, $item_name) { return false; } +/** + * Convenience function for registering an add content button to title menu + * + * The add URL must be $handler/add/$guid where $guid is the guid of the page owner. + * The label of the button is "$handler:add" so that must be defined in a + * language file. + * + * @param string $handler The handler to use or null to autodetect from context + * @return void + * @since 1.8.0 + */ +function elgg_register_add_button($handler = null) { + if (elgg_is_logged_in()) { + + 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' => 'add', + 'href' => "$handler/add/$guid", + 'text' => elgg_echo("$handler:add"), + 'link_class' => 'elgg-button elgg-button-action', + )); + } + } +} + /** * Adds a breadcrumb to the breadcrumbs stack. * -- cgit v1.2.3