From 029a67e6acd069cddce1ea5f8e515e1866053317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20R=C3=BCtter?= Date: Thu, 25 Jun 2026 21:29:02 +0000 Subject: [PATCH] Prevent icon fieldtype from crashing when the stored icon is missing IconSet::get() loaded the SVG with no existence check, so a stored icon value that no longer exists in the configured set (e.g. icons removed in the v5 to v6 redesign) threw a FileNotFoundException and 500'd the page. Return null for a missing icon instead; Icon::augment() already treats null as an empty value. --- src/Icons/IconSet.php | 8 ++++++-- tests/Fieldtypes/IconTest.php | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Icons/IconSet.php b/src/Icons/IconSet.php index d10e3a05cc6..dc9004c5eb4 100644 --- a/src/Icons/IconSet.php +++ b/src/Icons/IconSet.php @@ -38,9 +38,13 @@ public function contents() return $this->files()->map->getContents()->all(); } - public function get(string $name): string + public function get(string $name): ?string { - return $this->filesystem->get($this->directory.'/'.$name.'.svg'); + $path = $this->directory.'/'.$name.'.svg'; + + return $this->filesystem->exists($path) + ? $this->filesystem->get($path) + : null; } private function files(): Collection diff --git a/tests/Fieldtypes/IconTest.php b/tests/Fieldtypes/IconTest.php index c464446bf3a..102c8f2245a 100644 --- a/tests/Fieldtypes/IconTest.php +++ b/tests/Fieldtypes/IconTest.php @@ -27,6 +27,12 @@ public function it_accepts_svg_strings() $this->assertStringContainsString('assertNull($this->fieldtype()->augment('this-icon-does-not-exist')); + } + private function fieldtype($config = []) { return (new Icon)->setField(new Field('test', array_merge(['type' => 'icon'], $config)));