Skip to content

Commit

Permalink
Simplify People Picker on External Identity relinking form (CFM-125)
Browse files Browse the repository at this point in the history
  • Loading branch information
arlen committed Apr 13, 2026
1 parent 17baa93 commit 492afbc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion app/resources/locales/en_US/field.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 17 additions & 1 deletion app/src/Controller/ExternalIdentitiesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']]));

Expand All @@ -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])]));
Expand Down
16 changes: 0 additions & 16 deletions app/src/Lib/Util/StringUtilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -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).
*
Expand Down
3 changes: 1 addition & 2 deletions app/templates/ExternalIdentities/relink.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@
?>
<ul id="edit_ei-relink" class="fields form-list">
<?php
$this->Form->unlockField('target_person_id');
$vv_autocomplete_arguments = [
'fieldName' => 'target_person_id',
'fieldLabel' => __d('field', 'ExternalIdentitySources.target_person_id'),
'fieldLabel' => __d('field', 'ExternalIdentities.target_person_id'),
'autocomplete' => [
'configuration' => [
'action' => 'GET',
Expand Down

0 comments on commit 492afbc

Please sign in to comment.