diff --git a/ProcessMaker/Models/ProcessRequestToken.php b/ProcessMaker/Models/ProcessRequestToken.php
index 85ce41d136..0957cef697 100644
--- a/ProcessMaker/Models/ProcessRequestToken.php
+++ b/ProcessMaker/Models/ProcessRequestToken.php
@@ -4,6 +4,7 @@
use Carbon\Carbon;
use DB;
+use Exception;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Notification;
@@ -135,6 +136,7 @@ class ProcessRequestToken extends ProcessMakerModel implements TokenInterface
*/
protected $appends = [
'advanceStatus',
+ 'elementDestination'
];
/**
@@ -287,21 +289,42 @@ public function assignableUsers()
}
/**
- * Get the BPMN definition of the element where the token is.
+ * Returns either the owner element or its properties
*
- * @return array|\ProcessMaker\Nayra\Contracts\Bpmn\EntityInterface
+ * @param asObject Boolean flag that determines whether the function should return the element directly or its
+ * properties as an object.
+ *
+ * @return If the parameter is true, the function will return the object. If is false, the
+ * function will return the properties of the object.
*/
- public function getDefinition($asObject = false, $par = null)
+ private function getDefinitionFromOwner($asObject)
{
- if ($this->getOwner() && $this->getOwnerElement()) {
- $element = $this->getOwnerElement();
+ $element = $this->getOwnerElement();
- return $asObject ? $element : $element->getProperties();
- }
+ return $asObject ? $element : $element->getProperties();
+ }
+
+ /**
+ * Retrieves a specific element's BPMN definition from a request object and returns either the element
+ * itself or its properties.
+ *
+ * @param asObject Boolean flag that determines whether the function should return the BPMN element instance
+ * as an object or just its properties.
+ *
+ * @return If `asObject` is false, the properties of the BPMN element instance are returned.
+ */
+ private function getDefinitionFromRequest($asObject)
+ {
$request = $this->processRequest ?: $this->getInstance();
+
+ if (!$request) {
+ return [];
+ }
+
$process = $request->processVersion ?: $request->process;
$definitions = $process->getDefinitions();
$element = $definitions->findElementById($this->element_id);
+
if (!$element) {
return [];
}
@@ -309,6 +332,20 @@ public function getDefinition($asObject = false, $par = null)
return $asObject ? $element->getBpmnElementInstance() : $element->getBpmnElementInstance()->getProperties();
}
+ /**
+ * Get the BPMN definition of the element where the token is.
+ *
+ * @return array|\ProcessMaker\Nayra\Contracts\Bpmn\EntityInterface
+ */
+ public function getDefinition($asObject = false, $par = null)
+ {
+ if ($this->getOwner() && $this->getOwnerElement()) {
+ return $this->getDefinitionFromOwner($asObject);
+ }
+
+ return $this->getDefinitionFromRequest($asObject);
+ }
+
/**
* Get the BPMN element node where the token is currently located.
*
@@ -1152,4 +1189,71 @@ public function reassign($toUserId, User $requestingUser)
$this->user->notify($notification);
event(new ActivityAssigned($this));
}
+
+ private function getElementDestination($elementDestinationType, $elementDestinationProp)
+ {
+ $elementDestination = null;
+
+ switch ($elementDestinationType) {
+ case 'customDashboard':
+ case 'externalURL':
+ if (array_key_exists('value', $elementDestinationProp)) {
+ if (is_string($elementDestinationProp['value'])) {
+ $elementDestination = $elementDestinationProp['value'];
+ } else {
+ $elementDestination = $elementDestinationProp['value']['url'] ?? null;
+ }
+ }
+ break;
+ case 'taskList':
+ $elementDestination = route('tasks.index');
+ break;
+ case 'homepageDashboard':
+ if (hasPackage('package-dynamic-ui')) {
+ $user = auth()->user();
+ $elementDestination = \ProcessMaker\Package\PackageDynamicUI\Models\DynamicUI::getHomePage($user);
+ } else {
+ $elementDestination = route('home');
+ }
+ break;
+ case 'processLaunchpad':
+ $elementDestination = route('process.browser.index', [
+ 'process' => $this->process_id,
+ 'categorySelected' => -1
+ ]);
+ break;
+ case 'taskSource':
+ $elementDestination = $elementDestinationType;
+ break;
+ default:
+ $elementDestination = null;
+ break;
+
+ }
+
+ return $elementDestination;
+ }
+
+ /**
+ * Determines the destination URL based on the element destination type specified in the definition.
+ *
+ * @return string|null
+ */
+ public function getElementDestinationAttribute(): ?string
+ {
+ $definition = $this->getDefinition();
+ $elementDestinationProp = $definition['elementDestination'] ?? null;
+ $elementDestinationType = null;
+
+ try {
+ $elementDestinationProp = json_decode($elementDestinationProp, true);
+ if (is_array($elementDestinationProp) && array_key_exists('type', $elementDestinationProp)) {
+ $elementDestinationType = $elementDestinationProp['type'];
+ }
+ } catch (Exception $e) {
+ return null;
+ }
+
+ return $this->getElementDestination($elementDestinationType, $elementDestinationProp);
+ }
}
diff --git a/resources/js/processes-catalogue/components/ProcessTab.vue b/resources/js/processes-catalogue/components/ProcessTab.vue
index c327460d78..d5b451733a 100644
--- a/resources/js/processes-catalogue/components/ProcessTab.vue
+++ b/resources/js/processes-catalogue/components/ProcessTab.vue
@@ -29,6 +29,7 @@