Skip to content

Commit

Permalink
RSESPRT-246: Display custom error if activityID is not present in URL
Browse files Browse the repository at this point in the history
  • Loading branch information
olayiwola-compucorp committed May 31, 2024
1 parent b0a4ba0 commit 241d80d
Showing 1 changed file with 38 additions and 21 deletions.
59 changes: 38 additions & 21 deletions CRM/CiviAwards/Form/AwardReview.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,36 +117,53 @@ public function setDefaultValues() {
* {@inheritDoc}
*/
public function preProcess() {
if ($this->_action & CRM_Core_Action::ADD) {
$this->caseId = CRM_Utils_Request::retrieve('case_id', 'Positive', $this);
try {
if ($this->_action & CRM_Core_Action::ADD) {
$this->caseId = CRM_Utils_Request::retrieve('case_id', 'Positive', $this);
}
else {
$this->activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
$this->activity = $this->getActivity();
$this->caseId = CRM_Utils_Array::first($this->activity['case_id']);
}

$this->profileId = $this->getProfileIdFromCaseType();
$this->caseContactDisplayName = $this->getCaseContactDisplayName();
$this->caseTypeName = $this->getCaseTypeName();
$this->caseTags = $this->loadCaseTags();
}
else {
$this->activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
$this->activity = $this->getActivity();
$this->caseId = CRM_Utils_Array::first($this->activity['case_id']);
catch (\Throwable $th) {
$errorMessage = ts('An error occurred, ensure review URL is correct');
if ($this->isReviewFromSsp()) {
drupal_set_message($errorMessage, 'error');
}
else {
CRM_Core_Session::setStatus($errorMessage, 'Error', 'error');
}
CRM_Utils_System::redirect(CRM_Core_Session::singleton()->readUserContext());
}

$this->profileId = $this->getProfileIdFromCaseType();
$this->caseContactDisplayName = $this->getCaseContactDisplayName();
$this->caseTypeName = $this->getCaseTypeName();
$this->caseTags = $this->loadCaseTags();
}

/**
* {@inheritDoc}
*/
public function buildQuickForm() {
$this->fields = CRM_Core_BAO_UFGroup::getFields(
$this->profileId, FALSE, CRM_Core_Action::ADD, NULL,
NULL, FALSE, NULL, FALSE, 'AwardReview', CRM_Core_Permission::CREATE, 'weight'
);

$error = $this->getErrorMessage();
if ($error) {
$this->displayErrorMessage($error);
try {
$this->fields = CRM_Core_BAO_UFGroup::getFields(
$this->profileId, FALSE, CRM_Core_Action::ADD, NULL,
NULL, FALSE, NULL, FALSE, 'AwardReview', CRM_Core_Permission::CREATE, 'weight'
);

$error = $this->getErrorMessage();
if ($error) {
$this->displayErrorMessage($error);
}
else {
$this->displayReviewForm();
}
}
else {
$this->displayReviewForm();
catch (\Throwable $th) {
$this->displayErrorMessage(ts('An error occurred, ensure review URL is correct'));
}
}

Expand Down

0 comments on commit 241d80d

Please sign in to comment.