From 18f1410e61f1b31e632dbc90baea018e45311779 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Thu, 4 Sep 2025 12:48:30 +0300 Subject: [PATCH] Fix Breadcrumb failing linkTable query --- app/src/Controller/Component/BreadcrumbComponent.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/Controller/Component/BreadcrumbComponent.php b/app/src/Controller/Component/BreadcrumbComponent.php index 44e24920c..469b417a3 100644 --- a/app/src/Controller/Component/BreadcrumbComponent.php +++ b/app/src/Controller/Component/BreadcrumbComponent.php @@ -215,7 +215,14 @@ public function injectPrimaryLink(object $link, bool $index=true, string $linkLa $linkTable = TableRegistry::getTableLocator()->get($modelPath); $contain = method_exists($linkTable, $containsList) ? $linkTable->$containsList() : []; - $linkObj = $linkTable->get($link->value, ['contain' => $contain]); + $modelNameForeignKey = StringUtilities::classNameToForeignKey($modelsName); + $linkAttr = $link->attr == $modelNameForeignKey ? 'id' : $link->attr; + $linkObj = $linkTable + ->find() + ->where(["$modelsName.$linkAttr" => $link->value]) + ->contain($contain) + ->firstOrFail(); + if($index) { // We need to determine the primary link of the parent, which might or might @@ -271,6 +278,9 @@ public function injectPrimaryLink(object $link, bool $index=true, string $linkLa catch(\Exception $e) { // If anything goes wrong we don't want to crash the entire page $this->llog('error', "Breadcrumbs failed: " . $e->getMessage()); + $this->llog( + 'error', + "Breadcrumbs failed: " . json_encode($e->getTrace(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); } }