With reference to: http://drupal.org/node/84239
Rational: "force" user to select a group when register.
Suggested implementation:
1. add next line to og_user function (group.module file) within case 'register' just before return $form;:
$form['og_register']['og_register']['#validate'] = array('og_mandatory_group_registration_validate' =>
array());
2. Add next function to og_mandatory_group.module
function og_mandatory_group_registration_validate($form_id) {
if (count($form_id['#value']) == 1 && ($form_id['#value'][0] == 1)) {
form_set_error('og_register',"You must join at least one group");
}
}
3. GIU enhancement is needed to accommodate the new mode. Below list is a suggestion:
a. default group (the current)
b. at least one group should be selected
c. mixed of the above (i.e. at least one group, but the admin could set up a default group)
| Comment | File | Size | Author |
|---|---|---|---|
| #30 | require_num_groups_30.diff.txt | 9.05 KB | pwolanin |
| #23 | require_num_groups_22.diff.txt | 7.77 KB | pwolanin |
| #20 | require_num_groups_20.diff.txt | 7.35 KB | pwolanin |
| #17 | require_num_groups_3.diff.txt | 6.07 KB | pwolanin |
| #9 | require_num_groups_2.diff | 3.67 KB | pwolanin |
Comments
Comment #1
pwolanin commentedOk, to clarify, if you want to implement these features via og_mandatory_group, then all the code additions will only be to this module (none to og itself). So you need to add the validation funtion to the form, maybe like follows (I'm not sure if this will work):
Comment #2
pwolanin commentedfrom e-mail:
From my look at the hook_user API, $form will be empty. The $form that is returned is recursively merged with the existing $form array.
did you try this and it doesn't work?
Comment #3
esadot commentedSorry to say, it doesn’t.
The $form carries entire data in og_user function, however it's empty at og_mandatory_group_user. I guess I’d expected the $form to have the same "behavior". Am I missing something?
This is the new, not-working, code I merged (in bold):
function og_mandatory_group_user($op, &$edit, &$account, $category = NULL) {
if(!module_exist('og')){
return;
}
switch ($op) {
case 'register':
$form['og_register']['og_register']['#validate'] = array('og_mandatory_group_registration_validate' => array());
break;
case 'insert':
function og_mandatory_group_registration_validate($form_id) {
if (count($form_id['#value']) == 1 && ($form_id['#value'][0] == 1)) {
form_set_error('og_register',"You must join at least one group");
}
Comment #4
esadot commentedClarification for the above comment: og_mandatory_group_registration_validate function is not even reached.
Comment #5
pwolanin commenteddo you return $form (as in#1 above)?
Comment #6
esadot commentedYes I did. It didn't work.
Comment #7
pwolanin commentedI didn't pay close attention to the above- you have the wrong definition for the validate function. Look back at the code I have in the forum topic and compare.
Anyhow, an initial patch is attached. It adds the validation function and forces at least one group to be choosen. Of course, this doesn't take into account that there may be zero groups in the registration form. Also, there is some funky code in og.module, which is why i had to put the "unset" in there. Will file an issue against OG.
Comment #8
pwolanin commentedoops- don't use that pathc- it overrides all the other validation for the registration for.
Just found one easier way- implement the "validate" op of hook_user.
Comment #9
pwolanin commentedtry this instead
Comment #10
esadot commentedI omitted the $form_values, $form from the validation function definition as in og module it pop ups some alarms. Anyway, it’s nice to see that we are making a progress.
I checked the patch and it seems to work.
I added check for zero groups, and zero groups at the registration form. It seems to work as well (in bold).
case 'register':
$group = db_fetch_object(db_query(db_rewrite_sql('SELECT n.nid, n.title, o.* FROM {node} n INNER JOIN {og} o ON n.nid = o.nid WHERE n.type IN ('. str_pad('', count(variable_get('og_node_types', array('og'))) * 5 - 1, "'%s',") .') AND o.register = 1 ORDER BY n.title'), variable_get('og_node_types', array('og'))));
if ($group != 0) {
$form['#validate'] = array('og_mandatory_group_registration_validate' => array());
$form['og_register']['minimum'] = array ('#value' => t('You must join at least one group.'),);
return $form;
}
break;
Comment #11
esadot commentedoops, just noticed patch #2. I tested #1.
Comment #12
esadot commentedI’ve tested patch #2. Seems to work. I added non-groups and empty groups at registration form checks.
Comment #13
pwolanin commentedI don't really think you need the query, the unset() deals with the bug in og.
Issue filed here against OG: http://drupal.org/node/85724
Comment #14
esadot commentedI believe you need the query to avoid the wording instruction “You must join at least one group." on the screen. If you won’t query, you’ll get the wording though no group is populated at the registration form.
Comment #15
pwolanin commentedOh yes, I see now. My approach for that would be to count the number of checkboxes in the form. However, to make that work, I think you'd need to implement hook_form_alter, rather than using hook_user('register').
Comment #16
esadot commentedSure, but as we have a working code in place, I rather keep it.
Comment #17
pwolanin commentedattached is a patch I'm fairly happy with vs. the 4.7 version.
note that there are some non-substantive formatting changes here as well.
added hook_form_alter, plus put a new check box in hook_settings
please test this out.
Comment #18
pwolanin commentedhmmm, after thinking more, I'm not really satisfied with this patch- if the mandatory group is in the form, its checkbox needs to be disabled.
The only way to do this (I think) is to use hook_form_alter to take it out of the options for the checkboxes and make it a separate checkbox element with the 'disabled' attribute. The advantage of this, of course, is that the counting of the other groups gets much simplified. However, some extra work may have to be done in hook_user.
Comment #19
esadot commented1. Well … if the mandatory group is in the form, I’d recommend its checkbox to be checked without the user ability to clear it.
2. The “Require new users to join at least one group in addition to any mandatory group” checkbox / feature doesn’t work when mandatory group (at setting) is NOT selected.
I believe two changes are needed:
a. following code in og_mandatory_group_form_alter ($form_id, &$form) function might be nested one unnecessary level, and $form['og_mandatory_in_form'] should not be cleared.
I believe it should be:
b. Next code (in validate case of og_mandatory_group_user function) is not been reached, which allow the user to register even though a group was not selected (and mandatory group in NOT selected at setting).
3. I think that we should offer two modes, and consider if a third one is necessary:
a. only mandatory group (already supported).
b. only join-at-least-one (need above bug fix).
c. mixed (personally, I’m not sure if it will have a demand).
4. In setting: if mandatory group is selected, then it’s not possible to disable the mandatory group, and only enable the “Require new users to join at least one group in addition to any mandatory group” without going through the “reset to default”
Comment #20
pwolanin commentedmcuh improved behavior in attached patch. Settings now include none as an option for the mandatory group. Also, the mandatory group appears as a selected, disabled checkbox in the registration form.
Comment #21
esadot commentedThe “none” is a very good option, however I suggest separating the mandatory group and join-at-least-one to two distinct configuration blocks. As it stands, the “none” looks as it pertains to the “Require new users to join …” checkbox as well.
May I suggest the following code at og_mandatory_group_settings():
Second, it seems that the mandatory group is not working. The “if” condition at og_mandatory_group_form_alter () does not yield true
Comment #22
pwolanin commentedyes, I agree about there needing to be some visual separation of the different settings.
Comment #23
pwolanin commentedok, I think I was messing up the group options by using array_merge. Try out the attached patch.
Comment #24
pwolanin commentedsee also this additioanl bug report for OG: http://drupal.org/node/86011
Comment #25
esadot commentedO yeah. Looks much better, though it’s kind of late now, and I haven’t had the chance to thoroughly test it. But, at first glace, it looks very good.
One feel&look issue: the checked checkbox of the mandatory group at registration form is too mild, hardly can be seen. I tested in all four themes that comes with Drupal, and a few others, all of which the checkbox can hardly been seen as checked. It would be nice if there is an option to “bold” the "v" sign.
Comment #26
pwolanin commentedI think the grayed-out check is the standard way the form elements look when they are disabled.
Comment #27
esadot commentedLooks good to me.
Please let me know upon upgrading the module, as I like to use this feature.
Comment #28
pwolanin commentedWell, since you've applied the patch, you can use it now! i'll probably do a little more testing before I actually commit the changes. If you have any suggestings for updating the README file to explain the new features, that would be very helpful.
Comment #29
esadot commentedOk, 1 2 3, testing, testing …
The organic group mandatory module is happy to announce a new feature; supports an option which obliged the end user to join at least one group during registration.
Usage: say you’ve established moderated groups, and populate them into the registration form: if you want to force a new user to join at least one group, then this is your lucky day.
Comment #30
pwolanin commentedhere's patch with an updated README file
Comment #31
pwolanin commentedany last feedback?
Comment #32
esadot commentedYes - thanks you very much :)
I’m content.
Emek
http://www.sadot.tv
Comment #33
pwolanin commentedcommitted the last patch.