From 82e728482d131cafce0d857b9e10a4e95473683b Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Mon, 21 Sep 2026 16:10:03 +0100 Subject: [PATCH] resolve addon settings file by the addon's slug `FileSettingsRepository::find()` derived the filename from the package name, while `FileSettings::path()` writes it under the addon's slug. Addons with a custom slug saved to one file and read from another. Co-Authored-By: Claude Fable 5.1 --- src/Addons/FileSettingsRepository.php | 18 +++++------------ tests/Addons/FileSettingsRepositoryTest.php | 22 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/Addons/FileSettingsRepository.php b/src/Addons/FileSettingsRepository.php index 1ec5df3b111..60f711c2b35 100644 --- a/src/Addons/FileSettingsRepository.php +++ b/src/Addons/FileSettingsRepository.php @@ -3,7 +3,6 @@ namespace Statamic\Addons; use Illuminate\Support\Facades\File; -use Illuminate\Support\Str; use Statamic\Addons\SettingsRepository as AbstractSettingsRepository; use Statamic\Contracts\Addons\Settings as AddonSettingsContract; use Statamic\Facades; @@ -13,15 +12,17 @@ class FileSettingsRepository extends AbstractSettingsRepository { public function find(string $addon): ?AddonSettingsContract { - $slug = Str::after($addon, '/'); + if (! $addon = Facades\Addon::get($addon)) { + return null; + } - $path = resource_path("addons/{$slug}.yaml"); + $path = resource_path("addons/{$addon->slug()}.yaml"); if (! File::exists($path)) { return null; } - return $this->makeFromPath($path); + return $this->make($addon, YAML::file($path)->parse()); } public function save(AddonSettingsContract $settings): bool @@ -40,15 +41,6 @@ public function delete(AddonSettingsContract $settings): bool return true; } - private function makeFromPath(string $path): AddonSettingsContract - { - $yaml = YAML::file($path)->parse(); - - $addon = Facades\Addon::all()->first(fn ($addon) => $addon->slug() === basename($path, '.yaml')); - - return $this->make($addon, $yaml); - } - public static function bindings(): array { return [ diff --git a/tests/Addons/FileSettingsRepositoryTest.php b/tests/Addons/FileSettingsRepositoryTest.php index 1a1dccb5c1a..e85d95726db 100644 --- a/tests/Addons/FileSettingsRepositoryTest.php +++ b/tests/Addons/FileSettingsRepositoryTest.php @@ -61,6 +61,28 @@ public function it_gets_addon_settings() $this->assertEquals(['foo' => 'bar', 'baz' => 'qux'], $settings->all()); } + /** + * @see https://github.com/statamic/cms/issues/15494 + */ + #[Test] + public function it_gets_addon_settings_when_the_slug_differs_from_the_package_name() + { + $addon = $this->makeFromPackage(['slug' => 'custom-slug']); + + Facades\Addon::shouldReceive('get')->with('vendor/test-addon')->andReturn($addon); + + File::put(resource_path('addons/custom-slug.yaml'), <<<'YAML' +foo: bar +baz: qux +YAML); + + $settings = $this->repository->find($addon->id()); + + $this->assertInstanceOf(FileSettings::class, $settings); + $this->assertEquals($addon, $settings->addon()); + $this->assertEquals(['foo' => 'bar', 'baz' => 'qux'], $settings->all()); + } + #[Test] public function it_saves_addon_settings() {