Skip to content

Commit 00603fd

Browse files
committed
refactor: migrate from custom config system to Statamic addon settings
Remove custom YAML-based configuration system and replace with Statamic's built-in addon settings. Delete settings.yaml, ConfigController, and Config model. Simplify HasConfig trait to use Addon::get()->settings() instead of custom file-based configuration. refactor: replace custom config routes with settings blueprint feat: add comprehensive settings blueprint with property ID, date range, and widget configuration options fix: update analytics route from google-analytics to isapp-analytics for consistency style: adjust declare statement spacing to match coding standards
1 parent 88dd4eb commit 00603fd

5 files changed

Lines changed: 100 additions & 290 deletions

File tree

resources/settings.yaml

Lines changed: 0 additions & 66 deletions
This file was deleted.

src/Concerns/HasConfig.php

Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -10,71 +10,18 @@
1010
* License: Commercial. See LICENSE.md.
1111
*/
1212

13-
declare(strict_types=1);
13+
declare(strict_types = 1);
1414

1515
namespace Isapp\GoogleAnalytics\Concerns;
1616

17-
use Illuminate\Support\Collection;
18-
use Illuminate\Support\Facades\File;
1917
use Isapp\GoogleAnalytics\Models\Config;
20-
use Statamic\Facades\YAML;
21-
22-
use function array_merge;
23-
use function storage_path;
18+
use Statamic\Facades\Addon;
2419

2520
trait HasConfig
2621
{
27-
protected function hydrateConfig($config): Collection
28-
{
29-
$defaultSiteHandle = 'default';
30-
31-
return collect($config)->map(
32-
fn ($config, $handle) => new Config($handle, $config, $handle === $defaultSiteHandle)
33-
);
34-
}
35-
36-
protected function setSites($sites = null): Collection
37-
{
38-
$sites ??= $this->getSavedSites();
39-
40-
return $this->hydrateConfig($sites);
41-
}
4222

4323
protected function values(): array
4424
{
45-
$sites ??= $this->getSavedSites();
46-
47-
$config = $this->hydrateConfig($sites)
48-
->keyBy
49-
->handle()
50-
->map
51-
->rawConfig()
52-
->all();
53-
54-
return collect($config)
55-
->map(fn ($site, $handle) => array_merge(['handle' => $handle], $site))
56-
->values()
57-
->first();
58-
}
59-
60-
protected function getSavedSites()
61-
{
62-
return File::exists($sitesPath = $this->path())
63-
? YAML::file($sitesPath)->parse()
64-
: $this->getFallbackConfig();
65-
}
66-
67-
protected function path(): string
68-
{
69-
return storage_path('app/private/google-analytics/google-analytics.yaml');
70-
}
71-
72-
protected function getFallbackConfig(): array
73-
{
74-
return [
75-
'default' => [
76-
'property_id' => config('analytics.property_id'),
77-
],
78-
];
25+
return Addon::get('isapp/statamic-analytics')->settings()->all();
7926
}
8027
}

src/Controllers/ConfigController.php

Lines changed: 0 additions & 115 deletions
This file was deleted.

src/Models/Config.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)