diff --git a/includes/registration.forms.inc b/includes/registration.forms.inc index e0abb58..385d6c9 100644 --- a/includes/registration.forms.inc +++ b/includes/registration.forms.inc @@ -1035,14 +1035,14 @@ function registration_convert_form_settings($values, $entity) { /** * Combines a relative date with the event date into a new date value. * - * @param reference $field + * @param &$field * Reference to the field that will be converted. * @param string $event_date * Date of the event (base date for relative calculations). * @param string $relative_date * Relative date. */ -function registration_convert_relative_date(reference &$field, $event_date, $relative_date) { +function registration_convert_relative_date(&$field, $event_date, $relative_date) { if (!empty($relative_date)) { $field = date('Y-m-d H:i:s', strtotime($relative_date, $event_date)); } diff --git a/registration.module b/registration.module index 29303dc..766cbf0 100644 --- a/registration.module +++ b/registration.module @@ -804,10 +804,10 @@ function registration_event_count($entity_type, $entity_id, $registration_id = N function registration_entity_insert($entity, $entity_type) { $registration_type = registration_get_entity_registration_type($entity_type, $entity); if ($registration_type !== FALSE) { - registration_entity_set_default_settings($entity_type, $entity); list($entity_id) = entity_extract_ids($entity_type, $entity); - $settings = registration_entity_settings($entity_type, $entity_id); - registration_entity_update_relative_dates($entity_type, $entity, $settings); + if ($settings = registration_entity_get_default_settings($entity_type, $entity)) { + registration_entity_update_relative_dates($entity_type, $entity, $settings); + } } } @@ -830,23 +830,43 @@ function registration_entity_update($entity, $entity_type) { } /** - * Sets the the registration entity settings to the defaults. + * Gets the default registration entity settings. * * @param $entity_type * @param $entity + * + * @return array|NULL */ -function registration_entity_set_default_settings($entity_type, $entity) { - list($entity_id, , $bundle) = entity_extract_ids($entity_type, $entity); +function registration_entity_get_default_settings($entity_type, $entity) { + list(, , $bundle) = entity_extract_ids($entity_type, $entity); $registration_instances = registration_get_registration_instances(array( 'entity_type' => $entity_type, 'bundle' => $bundle )); + $settings = NULL; foreach ($registration_instances as $instance) { if (isset($instance['settings']['default_registration_settings'])) { + // Stash the settings so that we end up with the last set of default + // settings in the odd case that there are multiple. $settings = registration_convert_form_settings($instance['settings']['default_registration_settings'], $entity); - registration_update_entity_settings($entity_type, $entity_id, $settings); + $settings['settings'] = unserialize($settings['settings']); } } + return $settings; +} + + +/** + * Sets the the registration entity settings to the defaults. + * + * @param $entity_type + * @param $entity + */ +function registration_entity_set_default_settings($entity_type, $entity) { + list($entity_id) = entity_extract_ids($entity_type, $entity); + if ($settings = registration_entity_get_default_settings($entity_type, $entity)) { + registration_update_entity_settings($entity_type, $entity_id, $settings); + } } /** @@ -913,12 +933,9 @@ function registration_get_base_entity_date($entity_type, $entity, $date_field_na $field_items[0]['value'], $field_items[0]['timezone_db'] ); - $event_timestamp = $offset_date->getTimestamp(); + return $offset_date->getTimestamp(); } - else { - $event_timestamp = NULL; - } - return $event_timestamp; + return NULL; } /** @@ -1175,6 +1192,9 @@ function registration_send_broadcast($entity_type, $entity_id, $subject, $messag * Array keyed by field names from {registration_entity} */ function registration_update_entity_settings($entity_type, $entity_id, $settings) { + if (is_array($settings['settings'])) { + $settings['settings'] = serialize($settings['settings']); + } // Insert or update registration entity settings. db_merge('registration_entity') ->key(array(