I am working on making an independent plugin from the groups plugin to be schools plugin. It seems to work fine unless the problems appear in this page
1-
it started to duplicate the item called invite friends and the url for this items doesn't work.
I realized that the problem appear when I activate the two plugin at the same time .
This line of the code of the menu in the start.php file of the schools plugin I created.
elgg_register_plugin_hook_handler('register', 'menu:title', '_schools_title_menu');
the function :
function _schools_title_menu(\Elgg\Hook $hook) {
$group = $hook->getEntityParam();
if (!$group instanceof ElggGroup) {
return;
}
$user = elgg_get_logged_in_user_entity();
if (empty($user)) {
return;
}
$result = $hook->getValue();
if ($group->canEdit()) {
$url2= elgg_generate_url('edit:school:school', [
'guid' => $group->guid,
]);
$url=elgg_generate_entity_url($group, 'edit');
// group owners can edit the group and invite new members
$result[] = \ElggMenuItem::factory([
'name' => 'edit',
'icon' => 'edit',
'href' => $url2,
'text' => elgg_echo('schools:edit'),
'link_class' => 'elgg-button elgg-button-action',
]);
if (elgg_is_active_plugin('friends')) {
$result[] = \ElggMenuItem::factory([
'name' => 'schools:invite',
'icon' => 'user-plus',
'href' => elgg_generate_entity_url($group, 'invite'),
'text' => elgg_echo('schools:invite'),
'link_class' => 'elgg-button elgg-button-action',
]);
}
}
if ($group->isMember($user)) {
$is_owner = ($group->owner_guid === $user->guid);
$result[] = ElggMenuItem::factory([
'name' => 'group-dropdown',
'href' => false,
'text' => elgg_echo($is_owner ? 'schools:button:owned' : 'schools:button:joined'),
'link_class' => 'elgg-button elgg-button-action-done',
'child_menu' => [
'display' => 'dropdown',
],
'data-position' => json_encode([
'my' => 'right top',
'at' => 'right bottom',
]),
]);
$leave_group = schools_get_group_leave_menu_item($group, $user);
if ($leave_group instanceof ElggMenuItem) {
$leave_group->setParentName('group-dropdown');
$result[] = $leave_group;
}
} else {
$join_group = schools_get_group_join_menu_item($group, $user);
if ($join_group) {
$join_group->setLinkClass('elgg-button elgg-button-action');
$result[] = $join_group;
}
}
return $result;
}
Also As you can see above I changed the text of the button of edit on this menu to be edit school to be different from groups plugin
This line of the code of the menu in the start.php file of the groups plugin .
elgg_register_plugin_hook_handler('register', 'menu:title', '_groups_title_menu');
it's function:
function _groups_title_menu(\Elgg\Hook $hook) {
$group = $hook->getEntityParam();
if (!$group instanceof ElggGroup) {
return;
}
$user = elgg_get_logged_in_user_entity();
if (empty($user)) {
return;
}
$result = $hook->getValue();
if ($group->canEdit()) {
// group owners can edit the group and invite new members
$url=elgg_generate_entity_url($group,);
$result[] = \ElggMenuItem::factory([
'name' => 'edit',
'icon' => 'edit',
'href' => elgg_generate_entity_url($group, 'edit'),
'text' => elgg_echo('groups:edit'),
'link_class' => 'elgg-button elgg-button-action',
]);
if (elgg_is_active_plugin('friends')) {
$result[] = \ElggMenuItem::factory([
'name' => 'groups:invite',
'icon' => 'user-plus',
'href' => elgg_generate_entity_url($group, 'invite'),
'text' => elgg_echo('groups:invite'),
'link_class' => 'elgg-button elgg-button-action',
]);
}
}
if ($group->isMember($user)) {
$is_owner = ($group->owner_guid === $user->guid);
$result[] = ElggMenuItem::factory([
'name' => 'group-dropdown',
'href' => false,
'text' => elgg_echo($is_owner ? 'groups:button:owned' : 'groups:button:joined'),
'link_class' => 'elgg-button elgg-button-action-done',
'child_menu' => [
'display' => 'dropdown',
],
'data-position' => json_encode([
'my' => 'right top',
'at' => 'right bottom',
]),
]);
$leave_group = groups_get_group_leave_menu_item($group, $user);
if ($leave_group instanceof ElggMenuItem) {
$leave_group->setParentName('group-dropdown');
$result[] = $leave_group;
}
} else {
$join_group = groups_get_group_join_menu_item($group, $user);
if ($join_group) {
$join_group->setLinkClass('elgg-button elgg-button-action');
$result[] = $join_group;
}
}
return $result;
}
If I just deactivate the groups plugin or remove the menu item from groups plugin it appears correctly as you can see in image below
I really need some help as I am getting confused.
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by Raül Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- Nikolai Shcherbin@rivervanrain

Nikolai Shcherbin - 0 likes
- C0Rrupt@thjMMvw

C0Rrupt - 0 likes
- Reuven@reuven

Reuven - 1 like
You must log in to post replies.It's because you're using the same entity via ElggGroup class.
You should extend this class in the custom plugin and then call your new entity.
There're other things to do but start with class extending.
Please learn Elgg docs (especially Related section there).
Elgg docs also has Copy a plugin FAQ.
There're same discussions about cloning group: 1, 2
They may be old but will give you some ideas of what to do.
I just want to say that the OP deserves a more complete answer than "Please learn Elgg docs ". As someone who has spent many years studying and learning elgg, I find the documentation to be hard, sometimes impossible, to implement. Such a statement is offensive and negatively affects one's attitude toward adoption of the elgg framework. A (far) more helpful response would be to actually look at the code that Ahmed posted and recommend a correction that he can use. Like, copy/paste use. I would dearly like to see answers that are as thoughtful and helpful as what one might get at StackOverflow.com. That should be our aspiration.
Short or long answers, with or without code, there are many types of answers. Community members are taking the time from their busy schedule and doing the best to give good and helpful answers. We should be very grateful for every answer.
Look what Nikolai did in his above answer. First of all he gave a valid answer. Then he searched the Docs and gave the link. Then he made a general search and recommended a useful discussion and gave the link. All this takes time and you get it for free. And he have been answering many questions for long time.
Fortunately, there are more community members that answer questions. Usually, I get good answers, and feel uncomfortable that I can not return as much.
Anyway, thank you for your comment. It gave me the opportunity to thank this good people :)