Hello.
I am trying to write a plugin (Elgg 2.2.1), that, after a new user validates registration by email (and only after the user is validated), creates a new group based on some of the data submitted by registration form and joins the user to this new group. Also, the new group should not be created and owned by newly registered user, but by special "administrator" user, which is intended owner of all the groups created in such manner.
I tried doing it like this:
in start.php:
elgg_register_plugin_hook_handler( 'action', 'uservalidationbyemail/validate', 'validate_action_hook' );
function validate_action_hook($hook, $type, $value, $params) {
$user = elgg_get_logged_in_user_entity();
if( elgg_get_user_validation_status($user->guid) == true ) {
$userdata1 = $user->data1;
$userdata2 = $user->data2;
$groupname = $address.' '.$city;
$group = elgg_get_entities_from_metadata( array( 'type' => 'group', 'metadata_name_value_pairs' => array( array( 'name' => 'name', 'value' => $groupname ) ) ) );
if( !elgg_instanceof($group, 'group') ) {
$gdesc = $groupname;
$group_owner_guid = elgg_get_entities_from_metadata( array( 'type' => 'user', 'metadata_name_value_pairs' => array( array( 'name' => 'username', 'value' => 'administrator' ) ) ) )->guid;
$group = new ElggGroup();
$group->subtype = 'subtype1';
$group->name = $groupname;
$group->description = $gdesc;
$group->membership = ACCESS_PRIVATE;
$group->owner_guid = $group_owner_guid;
$group->save();
}
$group->join( $user );
return true;
}
return false;
}
Unfortunately, this doesn't work, and the Elgg documentation wasn't very helpful with providing me the right answers.
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.
Group tools plugin has a same option
Thanks for pointing me in that direction. However it doesn't exactly provide what I need, but at least I can use it as an example to achieve what I want to accomplish.
I'm still stuck. I couldn't find anywhere in group tools plugin how to trigger group creation after the 'uservalidationbyemail/validate' action. This problem is setting back my project big time. Please help, what am I doing wrong?
Listen to 'create', 'metadata' event:
Or you could also listen to the 'forward', 'all' hook, sniff the route to see if it's action/uservalidationbyemail/validate and do stuff then.
I created an issue as it's a solid use case https://github.com/Elgg/Elgg/issues/10576
Thank you, Ismayil.
I tried your suggestions, but still, no joy. On top of that, debugging such hooks in Elgg is real PITA. I am beginning to regret choosing Elgg as my project platform, as the time spent developing this lone plugin is approaching the time I would have spent making it all from scratch in say MODX, which I am quite proficient with, has much better documentation and way more transparent modular structure, or in fewer words, it's incomparably more developer friendly than I found Elgg to be. Besides, no Elgg devs even sniffed the Github issue you created. Thank you again for taking your time with my problem, sadly it more and more looks it was all in vain.
Best regards,
ZP
What didn't work? You are not getting an entity (did you try enabling hidden entities)? Or the event is not called?
Well, it would have been definitely faster if you just made a pull request against core with the event trigger you need, instead of waiting for others to do it. I created the issue and will most likely be the one to fix it eventually, but I am overworked at the moment.
You can always create your own validation plugin, or just fork it.
In 3.0, we are moving towards OO hook handling, so it should be easier to debug, but alas for now we are stuck with what we have.
I made the PR for you, but it probably won't make it into core until 3.0.
https://github.com/Elgg/Elgg/pull/10626
Hi Ismayil.
After a bit of tinkering with elgg_set_ignore_access and access_show_hidden_entities I finally got it to work, however I have a new problem:
$groupList = elgg_get_entities_from_metadata( array( 'type' => 'group', 'subtype' => $my_subtype, 'metadata_name_value_pairs' => array( array( 'name' => 'name', 'operand' => '=', 'value' => $groupname, 'case_sensitive' => false ) ) ) );
elgg_dump( $groupList );
Returns an empty array, even though the group with $groupname exists, so I end up with duplicate groups for each new user, instead of (new) user joining the existing group. Tried also with omitting 'subtype' => $my_subtype, same result.
Thanks for your help, much appreciated.
BR,
ZP
- Previous
- 1
- 2
- Next
You must log in to post replies.