function party_hat_party_form_hat_submit in Party 8.2
Same name and namespace in other branches
- 7 modules/party_hat/party_hat.module \party_hat_party_form_hat_submit()
Trigger Rules etc when a hat is assigned.
1 string reference to 'party_hat_party_form_hat_submit'
- party_hat_form_party_edit_form_alter in modules/
party_hat/ party_hat.module - Imlements hook_form_FORM_ID_alter.
File
- modules/
party_hat/ party_hat.module, line 734 - party_hat.module Provides an extensible access system for parties.
Code
function party_hat_party_form_hat_submit($form, &$form_state) {
$party_unchanged = $form_state['#party_unchanged'];
$party = $form_state['#party'];
$old_hats = array_keys(party_hat_get_hats($party_unchanged));
$hats = array_keys(party_hat_get_hats($party));
$all_hats = array_merge($old_hats, $hats);
$assigned_hats = array();
$unassigned_hats = array();
foreach (array_diff($old_hats, $hats) as $hat_name) {
$unassigned_hats[] = $hat_name;
}
foreach (array_diff($hats, $old_hats) as $hat_name) {
$assigned_hats[] = $hat_name;
}
unset($hats, $old_hats);
//invoke hooks and rules to unassign hats
if (!empty($unassigned_hats)) {
if (module_exists('rules')) {
rules_invoke_all('party_hat_unassign_hats', $party, $unassigned_hats);
}
else {
module_invoke_all('party_hat_unassign_hats', $party, $unassigned_hats);
}
}
// invoke hooks and rules to assign hats
if (!empty($assigned_hats)) {
if (module_exists('rules')) {
rules_invoke_all('party_hat_assign_hats', $party, $assigned_hats);
}
else {
module_invoke_all('party_hat_assign_hats', $party, $assigned_hats);
}
}
}