From 492afbc4db05c143c9b672c8c10c3d716a6184bb Mon Sep 17 00:00:00 2001 From: Arlen Johnson Date: Mon, 13 Apr 2026 11:47:39 -0400 Subject: [PATCH] Simplify People Picker on External Identity relinking form (CFM-125) --- app/resources/locales/en_US/field.po | 2 +- .../ExternalIdentitiesController.php | 18 +++++++++++++++++- app/src/Lib/Util/StringUtilities.php | 16 ---------------- app/templates/ExternalIdentities/relink.php | 3 +-- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/app/resources/locales/en_US/field.po b/app/resources/locales/en_US/field.po index d92e00392..4eab6c73b 100644 --- a/app/resources/locales/en_US/field.po +++ b/app/resources/locales/en_US/field.po @@ -573,7 +573,7 @@ msgstr "Redirect on Duplicate" msgid "EnrollmentFlows.redirect_on_finalize" msgstr "Redirect on Finalize" -msgid "ExternalIdentitySources.target_person_id" +msgid "ExternalIdentities.target_person_id" msgstr "Target Person" msgid "ExternalIdentitySources.hash_source_record" diff --git a/app/src/Controller/ExternalIdentitiesController.php b/app/src/Controller/ExternalIdentitiesController.php index 7ccdff678..cc161fca0 100644 --- a/app/src/Controller/ExternalIdentitiesController.php +++ b/app/src/Controller/ExternalIdentitiesController.php @@ -114,7 +114,7 @@ public function relink(string $id) { try { $Pipelines = TableRegistry::getTableLocator()->get('Pipelines'); - $Pipelines->relink((int)$id, StringUtilities::extractPeoplePickerPersonId($reqData['target_person_id'])); + $Pipelines->relink((int)$id, (int)$reqData['target_person_id']); $this->Flash->success(__d('result', 'ExternalIdentities.relinked', [$id, $reqData['target_person_id']])); @@ -133,6 +133,22 @@ public function relink(string $id) { } } + // The people picker expects a valid $vv_obj, so set it. + // (This is usually set in StandardController by the standard actions.) + $table = $this->getCurrentTable(); + $query = $table->findById($id); + + try { + $obj = $query->firstOrFail(); + } + catch(\Exception $e) { + // findById throws Cake\Datasource\Exception\RecordNotFoundException + $this->Flash->error($e->getMessage()); + return $this->generateRedirect(null); + } + + $this->set('vv_obj', $obj); + // Fall through to the view to render a People Picker $this->set('vv_title', __d('operation', 'relink.a', [__d('controller', 'ExternalIdentities', [1])])); diff --git a/app/src/Lib/Util/StringUtilities.php b/app/src/Lib/Util/StringUtilities.php index 4dd68ccc4..c7cce8012 100644 --- a/app/src/Lib/Util/StringUtilities.php +++ b/app/src/Lib/Util/StringUtilities.php @@ -396,22 +396,6 @@ private static function translateWithOverride( : $translated; } - /** - * Extract and return the Person ID from a People Picker string - * - * @since COmanage Registry v5.2.0 - * @param string $s Person string from the People Picker widget, e.g. "Jane+Doe+(ID:+2125)" - * @return int extracted Person ID (converted to int from the extracted string) - */ - - public static function extractPeoplePickerPersonId(string $s): int { - // Regular expression for handling People Picker input - $re = '/^.*\(ID: (\d+)\)$/m'; - // Extract the People Picker Person ID - preg_match_all($re, $s, $matchesTarget, PREG_SET_ORDER, 0); - return (int)$matchesTarget[0][1]; - } - /** * Determine the class name from a foreign key (eg: report_id -> Reports). * diff --git a/app/templates/ExternalIdentities/relink.php b/app/templates/ExternalIdentities/relink.php index 61ece15dd..521641e0e 100644 --- a/app/templates/ExternalIdentities/relink.php +++ b/app/templates/ExternalIdentities/relink.php @@ -46,10 +46,9 @@ ?>