From c17263341f4ea94667e2f480320dcfb8552b75a5 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Thu, 20 Aug 2026 08:39:50 +0300 Subject: [PATCH] Fix missing Person context in breadcrumbs on Confirm Deletion page.Fix BreadcrumbComponent primary key resolution and prevent duplicate foreign keys in standard view links. --- .../Component/BreadcrumbComponent.php | 6 +++--- app/src/Controller/PeopleController.php | 10 ++++++++-- app/templates/People/fields.inc | 2 +- app/templates/Standard/add-edit-view.php | 18 ++++++++++++++++-- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/app/src/Controller/Component/BreadcrumbComponent.php b/app/src/Controller/Component/BreadcrumbComponent.php index f09080c69..cee093773 100644 --- a/app/src/Controller/Component/BreadcrumbComponent.php +++ b/app/src/Controller/Component/BreadcrumbComponent.php @@ -295,10 +295,10 @@ public function injectPrimaryLink( $linkTable = \Cake\ORM\TableRegistry::getTableLocator()->get($linkModelFqn); $contain = $this->resolveContainList($linkTable, $mappedAction); - // Normalize attr (people_id → id when the attr matches the model’s own foreign key) + // Use the table alias for query building (avoid plugin-qualified names in SQL) $modelAlias = $linkTable->getAlias(); - $foreignKey = StringUtilities::classNameToForeignKey($modelAlias); - $linkAttr = ($link->attr === $foreignKey) ? 'id' : $link->attr; + + $linkAttr = (string)$linkTable->getPrimaryKey(); // Fetch the linked entity; if not found, handle gracefully $linkedEntity = $linkTable diff --git a/app/src/Controller/PeopleController.php b/app/src/Controller/PeopleController.php index 160f73766..3b71d4d03 100644 --- a/app/src/Controller/PeopleController.php +++ b/app/src/Controller/PeopleController.php @@ -146,10 +146,16 @@ public function confirmDelete(string $id) { 'PetitionerPetitions', 'PetitionHistoryRecords' ]; - - $person = $this->People->get((int)$id, contain: $contain); + $person = $this->People->get((int)$id, contain: $contain); $this->set('vv_person', $person); + + $this->Breadcrumb->injectTitleLink( + table: $this->People, + entity: $person, + action: 'edit', + label: $this->People->generateDisplayField($person) + ); $this->set('vv_title', __d('operation', 'delete.a',[$person->primary_name->full_name])); diff --git a/app/templates/People/fields.inc b/app/templates/People/fields.inc index ed7997ea5..3fc77a299 100644 --- a/app/templates/People/fields.inc +++ b/app/templates/People/fields.inc @@ -54,7 +54,7 @@ if($vv_action == 'add') { // The initial name must be primary 'names.0.primary_name' => true ]; -} elseif($vv_action == 'edit') { +} else { $a = $vv_obj->extract(['person_role_id', 'person_id']); $useDeleteSplashPage = true; diff --git a/app/templates/Standard/add-edit-view.php b/app/templates/Standard/add-edit-view.php index 53b0e90eb..0f197e01c 100644 --- a/app/templates/Standard/add-edit-view.php +++ b/app/templates/Standard/add-edit-view.php @@ -153,8 +153,22 @@ $perm = $vv_permissions[$linkModel][$t['link']['action']]; } - // Inject a link to the current object ID - $t['link']['?'][\App\Lib\Util\StringUtilities::entityToForeignKey($vv_obj)] = $vv_obj->id; + // This fixes the link in the gear icon in the Person Canvas view. + // Inject a link to the current object ID, unless an equivalent specific foreign key + // (like subject_person_id) is already provided in the query arguments. + $fk = \App\Lib\Util\StringUtilities::entityToForeignKey($vv_obj); + $hasFk = false; + if(!empty($t['link']['?'])) { + foreach($t['link']['?'] as $k => $v) { + if($v === $vv_obj->id && (str_ends_with($k, '_' . $fk) || $k === $fk)) { + $hasFk = true; + break; + } + } + } + if(!$hasFk) { + $t['link']['?'][$fk] = $vv_obj->id; + } } else { $perm = $vv_permissions[$t['link']['action']];