Last active
January 30, 2016 02:38
-
-
Save esimonetti/422fd2387281800964e7 to your computer and use it in GitHub Desktop.
PHP driven error messages in Sugar v7 - Works for sidecar and BWC modules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Assuming that $b is a valid bean instance... | |
// Assuming we are editing the record... | |
// On SugarApiException($app_strings[$error_app_label], null, null, 422, 'my_error_code_sample'); | |
// "my_error_code_sample" is displayed on the output as "error" | |
// $app_strings[$error_app_label] is displayed on the output as "error_message" | |
$error_app_label = 'LBL_MY_ERROR_MESSAGE'; | |
if(!empty($b->module_name) && isModuleBWC($b->module_name)) | |
{ | |
SugarApplication::appendErrorMessage($app_strings[$error_app_label]); | |
$urlParameters = array( | |
'module' => $b->module_name, | |
'action' => 'EditView' | |
); | |
if(!empty($b->id)) | |
{ | |
$urlParameters['record'] = $b->id; | |
} | |
$url = 'index.php?' . http_build_query($urlParameters); | |
SugarApplication::redirect($url); | |
} | |
else | |
{ | |
throw new SugarApiException($app_strings[$error_app_label], null, null, 422, 'my_error_code_sample'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment