Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 5 additions & 13 deletions src/Addons/FileSettingsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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 [
Expand Down
22 changes: 22 additions & 0 deletions tests/Addons/FileSettingsRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Loading