Skip to content

[CFM-274] Fix Breadcrumb failing linkTable query #332

Merged
merged 1 commit into from
Sep 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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