function registration_waitlist_entity_presave in Entity Registration 7
Same name and namespace in other branches
- 8.2 modules/registration_waitlist/registration_waitlist.module \registration_waitlist_entity_presave()
- 8 modules/registration_waitlist/registration_waitlist.module \registration_waitlist_entity_presave()
- 7.2 modules/registration_waitlist/registration_waitlist.module \registration_waitlist_entity_presave()
Implements hook_entity_presave().
File
- modules/
registration_waitlist/ registration_waitlist.module, line 109 - Entity Registration waitlist functionality
Code
function registration_waitlist_entity_presave($entity, $type) {
if ($type == 'registration') {
$errors = array();
$status = registration_status($entity->entity_type, $entity->entity_id, TRUE, $entity->count, $entity->registration_id, $errors);
if (registration_waitlist_is_active($entity->entity_type, $entity->entity_id, $errors)) {
$active_states = registration_get_active_states();
// Check that the state being saved is active
if (in_array($entity->state, $active_states)) {
// Check that the old state (if there is one) is not already active
if (isset($entity->original) && !in_array($entity->original->state, $active_states) || !isset($entity->original)) {
drupal_set_message(t('Registration placed on the wait list.'), 'status');
// Set the registration state to waitlist
$waitlist_state = registration_get_states(REGISTRATION_WAITLIST_STATE);
$entity->state = $waitlist_state
->identifier();
}
}
}
}
}