- if (!$skipRedirect) {
- // Redirect the form in case of error
- CRM_Core_Session::setStatus(ts('The membership cannot be saved.') .
- '<br/>' .
- ts('No valid membership status for given dates.'),
- ts('Save Error'), 'error');
- return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view',
- "reset=1&force=1&cid={$params['contact_id']}&selectedChild=member"
- ));
- }
- // Return the error message to the api
- $error = array();
- $error['is_error'] = ts('The membership cannot be saved. No valid membership status for given dates. Please provide at least start_date. Optionally end_date and join_date.');
- return $error;
+ // Redirect the form in case of error
+ // @todo this redirect in the BAO layer is really bad & should be moved to the form layer
+ // however since we have no idea how (if) this is triggered we can't safely move / remove it
+ // NB I tried really hard to trigger this error from backoffice membership form in order to test it
+ // and am convinced form validation is complete on that form WRT this error.
+ $errorParams = array(
+ 'message_title' => ts('No valid membership status for given dates.'),
+ 'legacy_redirect_path' => 'civicrm/contact/view',
+ 'legacy_redirect_query' => "reset=1&force=1&cid={$params['contact_id']}&selectedChild=member",
+ );
+ throw new CRM_Core_Exception(ts('The membership cannot be saved because the status cannot be calculated.'), 0, $errorParams);