diff --git a/ProcessMaker/Events/ProcessCompleted.php b/ProcessMaker/Events/ProcessCompleted.php index 7ce7866317..be95f14dae 100644 --- a/ProcessMaker/Events/ProcessCompleted.php +++ b/ProcessMaker/Events/ProcessCompleted.php @@ -17,6 +17,8 @@ class ProcessCompleted implements ShouldBroadcastNow private $processRequest; + public $endEventDestination; + /** * Create a new event instance. * @@ -26,6 +28,7 @@ public function __construct(ProcessRequest $processRequest) { $this->payloadUrl = route('api.requests.show', ['request' => $processRequest->getKey()]); $this->processRequest = $processRequest; + $this->endEventDestination = $processRequest->getElementDestination(); } /** diff --git a/ProcessMaker/Models/ProcessRequest.php b/ProcessMaker/Models/ProcessRequest.php index 5b1ec55308..c03ba2aa81 100644 --- a/ProcessMaker/Models/ProcessRequest.php +++ b/ProcessMaker/Models/ProcessRequest.php @@ -1053,4 +1053,23 @@ public function getProcessVersionAlternativeAttribute(): string | null return null; } + + /** + * Retrieves the destination of the first closed end event. + * + * @return ?string Returns a string value representing the element destination of the first closed end event. + */ + public function getElementDestination(): ?string + { + $endEvents = $this->tokens() + ->where('element_type', 'end_event') + ->where('status', 'CLOSED') + ->get(); + + if ($endEvents->count(0) === 0) { + return null; + } + + return $endEvents->first()->elementDestination; + } } diff --git a/ProcessMaker/Models/ProcessRequestToken.php b/ProcessMaker/Models/ProcessRequestToken.php index 0957cef697..2236e7a91d 100644 --- a/ProcessMaker/Models/ProcessRequestToken.php +++ b/ProcessMaker/Models/ProcessRequestToken.php @@ -1190,7 +1190,15 @@ public function reassign($toUserId, User $requestingUser) event(new ActivityAssigned($this)); } - private function getElementDestination($elementDestinationType, $elementDestinationProp) + /** + * Determines the destination based on the type of element destination property + * + * @param elementDestinationType Used to determine the type of destination for an element. + * @param elementDestinationProp Used to determine the properties of the destination for an element. + * + * @return string|null Returns the destination URL. + */ + private function getElementDestination($elementDestinationType, $elementDestinationProp): ?string { $elementDestination = null; diff --git a/resources/views/tasks/edit.blade.php b/resources/views/tasks/edit.blade.php index c8225a384e..2a586caf55 100644 --- a/resources/views/tasks/edit.blade.php +++ b/resources/views/tasks/edit.blade.php @@ -522,11 +522,17 @@ class="multiselect__tag-icon"> `element_id=${this.task.element_id}&` + `process_id=${this.task.process_id}`; }, - completed(processRequestId) { + completed(processRequestId, endEventDestination = null) { // avoid redirection if using a customized renderer - if(this.task.component && this.task.component === 'AdvancedScreenFrame') { + if (this.task.component && this.task.component === 'AdvancedScreenFrame') { return; } + + if (endEventDestination) { + this.redirect(endEventDestination); + return; + } + this.redirect(`/requests/${processRequestId}`); }, error(processRequestId) {