From 67c0b02248649e734d16cb95a02b1092467d9781 Mon Sep 17 00:00:00 2001
From: Sebastian Almberg <83243306+Sebbeben@users.noreply.github.com>
Date: Thu, 12 Feb 2026 21:51:30 +0100
Subject: [PATCH] Add configurable datasheet URL mode for KiCad API
New setting "Datasheet field links to PDF" in KiCad EDA settings.
When enabled (default), the datasheet field resolves to the actual
PDF attachment URL. When disabled, it links to the Part-DB page
(old behavior). Configurable via settings UI or EDA_KICAD_DATASHEET_AS_PDF env var.
---
src/Services/EDA/KiCadHelper.php | 14 +++++++++++---
src/Settings/MiscSettings/KiCadEDASettings.php | 5 +++++
translations/messages.en.xlf | 12 ++++++++++++
3 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/src/Services/EDA/KiCadHelper.php b/src/Services/EDA/KiCadHelper.php
index 882152dd..c526c1c7 100644
--- a/src/Services/EDA/KiCadHelper.php
+++ b/src/Services/EDA/KiCadHelper.php
@@ -44,6 +44,9 @@ class KiCadHelper
/** @var int The maximum level of the shown categories. 0 Means only the top level categories are shown. -1 means only a single one containing */
private readonly int $category_depth;
+ /** @var bool Whether to resolve actual datasheet PDF URLs (true) or use Part-DB page links (false) */
+ private readonly bool $datasheetAsPdf;
+
public function __construct(
private readonly NodesListBuilder $nodesListBuilder,
private readonly TagAwareCacheInterface $kicadCache,
@@ -55,6 +58,7 @@ class KiCadHelper
KiCadEDASettings $kiCadEDASettings,
) {
$this->category_depth = $kiCadEDASettings->categoryDepth;
+ $this->datasheetAsPdf = $kiCadEDASettings->datasheetAsPdf;
}
/**
@@ -216,9 +220,13 @@ class KiCadHelper
UrlGeneratorInterface::ABSOLUTE_URL
);
- //Try to find an actual datasheet attachment (by type name, attachment name, or PDF extension)
- $datasheetUrl = $this->findDatasheetUrl($part);
- $result["fields"]["datasheet"] = $this->createField($datasheetUrl ?? $partUrl);
+ //Try to find an actual datasheet attachment (configurable: PDF URL vs Part-DB page link)
+ if ($this->datasheetAsPdf) {
+ $datasheetUrl = $this->findDatasheetUrl($part);
+ $result["fields"]["datasheet"] = $this->createField($datasheetUrl ?? $partUrl);
+ } else {
+ $result["fields"]["datasheet"] = $this->createField($partUrl);
+ }
$result["fields"]["Part-DB URL"] = $this->createField($partUrl);
//Add basic fields
diff --git a/src/Settings/MiscSettings/KiCadEDASettings.php b/src/Settings/MiscSettings/KiCadEDASettings.php
index d8f1026d..29b579a2 100644
--- a/src/Settings/MiscSettings/KiCadEDASettings.php
+++ b/src/Settings/MiscSettings/KiCadEDASettings.php
@@ -43,4 +43,9 @@ class KiCadEDASettings
envVar: "int:EDA_KICAD_CATEGORY_DEPTH", envVarMode: EnvVarMode::OVERWRITE)]
#[Assert\Range(min: -1)]
public int $categoryDepth = 0;
+
+ #[SettingsParameter(label: new TM("settings.misc.kicad_eda.datasheet_link"),
+ description: new TM("settings.misc.kicad_eda.datasheet_link.help"),
+ envVar: "bool:EDA_KICAD_DATASHEET_AS_PDF", envVarMode: EnvVarMode::OVERWRITE)]
+ public bool $datasheetAsPdf = true;
}
\ No newline at end of file
diff --git a/translations/messages.en.xlf b/translations/messages.en.xlf
index 9c811a21..a15d27f1 100644
--- a/translations/messages.en.xlf
+++ b/translations/messages.en.xlf
@@ -9993,6 +9993,18 @@ Please note, that you can not impersonate a disabled user. If you try you will g
This value determines the depth of the category tree, that is visible inside KiCad. 0 means that only the top level categories are visible. Set to a value > 0 to show more levels. Set to -1, to show all parts of Part-DB inside a sigle cnategory in KiCad.
+
+
+ settings.misc.kicad_eda.datasheet_link
+ Datasheet field links to PDF
+
+
+
+
+ settings.misc.kicad_eda.datasheet_link.help
+ When enabled, the datasheet field in KiCad will link to the actual PDF file (if found). When disabled, it will link to the Part-DB page instead. The Part-DB page link is always available as a separate "Part-DB URL" field.
+
+ settings.behavior.sidebar