From 25b9d20788890492ab72a2a9bccd79dcaf2ad18c Mon Sep 17 00:00:00 2001 From: Teisha McRae Date: Mon, 2 Feb 2026 11:36:06 -0500 Subject: [PATCH 1/3] Update show() to handle templateID or processID from route --- .../Http/Controllers/TemplateController.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/ProcessMaker/Http/Controllers/TemplateController.php b/ProcessMaker/Http/Controllers/TemplateController.php index 6d272d6bef..4547c0eb2b 100644 --- a/ProcessMaker/Http/Controllers/TemplateController.php +++ b/ProcessMaker/Http/Controllers/TemplateController.php @@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Session; use ProcessMaker\Http\Controllers\Api\TemplateController as TemplateApiController; use ProcessMaker\Models\Process; +use ProcessMaker\Models\ProcessTemplates; use ProcessMaker\Models\ScreenTemplates; use ProcessMaker\Models\Template; use ProcessMaker\Templates\ProcessTemplate; @@ -76,6 +77,34 @@ public function configure(string $type, $request) public function show(Request $request) { + $id = $request->route('id'); + + $template = ProcessTemplates::find($id); + + if (!$template) { + // id might be a process id + $editingProcess = Process::where('id', $id)->where('is_template', 1)->first(); + if ($editingProcess && $editingProcess->uuid) { + $template = ProcessTemplates::where('editing_process_uuid', $editingProcess->uuid)->first(); + if ($template) { + return redirect()->route('modeler.template.show', ['id' => $template->id]); + } + } + abort(404); + } + + // If template has an editing process, show template modeler with that process id + if ($template->editing_process_uuid) { + $editingProcess = Process::where('uuid', $template->editing_process_uuid) + ->where('is_template', 1) + ->first(); + if ($editingProcess) { + Session::flash('_alert', json_encode(['success', __('The template was created.')])); + + return view('processes.modeler.showTemplate')->with('id', $editingProcess->id); + } + } + $templateApiController = new TemplateApiController(new Template); $response = $templateApiController->show('process', $request); Session::flash('_alert', json_encode(['success', __('The template was created.')])); From fa1c2aff8853f3a76348da9aa78c1ed7263fb6e2 Mon Sep 17 00:00:00 2001 From: Teisha McRae Date: Mon, 2 Feb 2026 11:51:10 -0500 Subject: [PATCH 2/3] Remove session flash alert --- ProcessMaker/Http/Controllers/TemplateController.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ProcessMaker/Http/Controllers/TemplateController.php b/ProcessMaker/Http/Controllers/TemplateController.php index 4547c0eb2b..df52d767fb 100644 --- a/ProcessMaker/Http/Controllers/TemplateController.php +++ b/ProcessMaker/Http/Controllers/TemplateController.php @@ -93,14 +93,12 @@ public function show(Request $request) abort(404); } - // If template has an editing process, show template modeler with that process id + // If template has an editing process, show template modeler with that process id (resuming existing session) if ($template->editing_process_uuid) { $editingProcess = Process::where('uuid', $template->editing_process_uuid) ->where('is_template', 1) ->first(); if ($editingProcess) { - Session::flash('_alert', json_encode(['success', __('The template was created.')])); - return view('processes.modeler.showTemplate')->with('id', $editingProcess->id); } } From 8666d3f45cd8e59e71c4819547f373606d01c6d0 Mon Sep 17 00:00:00 2001 From: Teisha McRae Date: Mon, 2 Feb 2026 12:06:51 -0500 Subject: [PATCH 3/3] Add editingProcess relationship --- ProcessMaker/Http/Controllers/TemplateController.php | 10 +++------- ProcessMaker/Models/ProcessTemplates.php | 11 +++++++++++ ProcessMaker/Templates/ProcessTemplate.php | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ProcessMaker/Http/Controllers/TemplateController.php b/ProcessMaker/Http/Controllers/TemplateController.php index df52d767fb..2eb536efb5 100644 --- a/ProcessMaker/Http/Controllers/TemplateController.php +++ b/ProcessMaker/Http/Controllers/TemplateController.php @@ -94,13 +94,9 @@ public function show(Request $request) } // If template has an editing process, show template modeler with that process id (resuming existing session) - if ($template->editing_process_uuid) { - $editingProcess = Process::where('uuid', $template->editing_process_uuid) - ->where('is_template', 1) - ->first(); - if ($editingProcess) { - return view('processes.modeler.showTemplate')->with('id', $editingProcess->id); - } + $editingProcess = $template->editingProcess; + if ($editingProcess) { + return view('processes.modeler.showTemplate')->with('id', $editingProcess->id); } $templateApiController = new TemplateApiController(new Template); diff --git a/ProcessMaker/Models/ProcessTemplates.php b/ProcessMaker/Models/ProcessTemplates.php index 11bf37e794..19a7016415 100644 --- a/ProcessMaker/Models/ProcessTemplates.php +++ b/ProcessMaker/Models/ProcessTemplates.php @@ -21,6 +21,17 @@ class ProcessTemplates extends Template public $process_category_id; + /** + * The process currently being used to edit this template (if any). + * + * @return BelongsTo + */ + public function editingProcess() + { + return $this->belongsTo(Process::class, 'editing_process_uuid', 'uuid') + ->where('processes.is_template', 1); + } + /** * Category of the process. * diff --git a/ProcessMaker/Templates/ProcessTemplate.php b/ProcessMaker/Templates/ProcessTemplate.php index a1eca1857d..369a53b056 100644 --- a/ProcessMaker/Templates/ProcessTemplate.php +++ b/ProcessMaker/Templates/ProcessTemplate.php @@ -74,7 +74,7 @@ public function index(Request $request) public function show($request) : array { $template = ProcessTemplates::find($request->id); - $process = Process::where('uuid', $template->editing_process_uuid)->where('is_template', 1)->first(); + $process = $template->editingProcess; // If a process exists with the template editing process uuid delete that process and create a new process // this ensures any updates to the template manifest will be reflected