function party_hat_party_form_hat_validate in Party 8.2
Same name and namespace in other branches
- 7 modules/party_hat/party_hat.module \party_hat_party_form_hat_validate()
Additional validate handler to check party form for expected attached entities.
This checks if all expected data sets are present and, if not, sends the user back to the form with a nice message.
1 string reference to 'party_hat_party_form_hat_validate'
- 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 707 - party_hat.module Provides an extensible access system for parties.
Code
function party_hat_party_form_hat_validate($form, $form_state) {
$expected_data_sets = array();
foreach (party_hat_get_hats($form_state['#party']) as $hid => $hat) {
$expected_data_sets += party_hat_get_hat_data_sets($hat);
}
$attached_entities = $form_state['#attached_entities'];
$existent_data_sets = array();
foreach ($attached_entities as $attached_entity) {
if (!in_array($attached_entity->data_set_name, $existent_data_sets)) {
$existent_data_sets[] = $attached_entity->data_set_name;
}
}
$missing_data_sets = array_diff($expected_data_sets, $existent_data_sets);
foreach ($missing_data_sets as $data_set_name) {
$data_set = party_get_data_set_info($data_set_name);
form_set_error(NULL, t("Party %party is expected to have a %data-set which wasn't present. Please enter the data now.", array(
'%party' => $form_state['#party']->label,
'%data-set' => $data_set['label'],
)));
}
}