Skip to content

Commit

Permalink
Fix Breadcrumb failing linkTable query (#332, CFM-274)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis authored Sep 9, 2025
1 parent e091a26 commit 47424a5
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion app/src/Controller/Component/BreadcrumbComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,17 @@ 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]);
// Use the table alias for query building (avoid plugin-qualified names in SQL)
$modelAlias = $linkTable->getAlias();

$modelNameForeignKey = StringUtilities::classNameToForeignKey($modelAlias);
$linkAttr = $link->attr == $modelNameForeignKey ? 'id' : $link->attr;
$linkObj = $linkTable
->find()
->where(["$modelAlias.$linkAttr" => $link->value])
->contain($contain)
->firstOrFail();


if($index) {
// We need to determine the primary link of the parent, which might or might
Expand Down Expand Up @@ -271,6 +281,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));
}
}

Expand Down

0 comments on commit 47424a5

Please sign in to comment.