Skip to content

Commit fade032

Browse files
committed
Taxonomies, Builder, Core V2 (#719)
1 parent 788346b commit fade032

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2255
-161
lines changed

README.md

Lines changed: 362 additions & 78 deletions
Large diffs are not rendered by default.

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
"filament/filament": "^3.2",
2525
"pharaonic/laravel-readable": "^1.0.5",
2626
"codeat3/blade-google-material-design-icons": "^1.0",
27-
"ryangjchandler/filament-progress-column": "^1.0",
28-
"spatie/laravel-sluggable": "^3.6"
27+
"ryangjchandler/filament-progress-column": "^1.0"
2928
},
3029
"autoload": {
3130
"psr-4": {
@@ -60,4 +59,4 @@
6059
"phpstan/extension-installer": true
6160
}
6261
}
63-
}
62+
}

config/core.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@
5555
],
5656
],
5757
],
58+
'category' => [
59+
'package' => 'Moox Category',
60+
'models' => [
61+
'Category' => [
62+
'api' => [
63+
'Index' => '',
64+
'Show' => '',
65+
'Update' => '',
66+
'Delete' => '',
67+
],
68+
],
69+
],
70+
],
5871
'core' => [
5972
'package' => 'Moox Core',
6073
'models' => [],
@@ -263,7 +276,6 @@
263276
],
264277
],
265278
],
266-
267279
'security' => [
268280
'package' => 'Moox Security',
269281
'models' => [
@@ -298,6 +310,19 @@
298310
],
299311
],
300312
],
313+
'tag' => [
314+
'package' => 'Moox Tag',
315+
'models' => [
316+
'Tag' => [
317+
'api' => [
318+
'Index' => '',
319+
'Show' => '',
320+
'Update' => '',
321+
'Delete' => '',
322+
],
323+
],
324+
],
325+
],
301326
'training' => [
302327
'package' => 'Moox Training',
303328
'models' => [

resources/lang/en/core.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
'slug' => 'Slug',
77
'item' => 'Item',
88
'all' => 'All',
9+
'cms' => 'CMS',
910
'content' => 'Content',
1011
'documents' => 'Documents',
1112
'articles' => 'Articles',
@@ -119,4 +120,14 @@
119120
'empty_trash' => 'Empty Trash',
120121
'trash_emptied_successfully' => 'Trash emptied successfully',
121122
'items_permanently_deleted' => '{0} No items were permanently deleted.|{1} One item was permanently deleted.|[2,*] :count items were permanently deleted.',
123+
'search' => 'Search',
124+
'filter' => 'Filter',
125+
'hard_delete' => 'Hard Delete',
126+
'hard_delete_selected' => 'Hard Delete selected',
127+
'hard_delete_bulk_confirmation' => 'Are you sure you want to hard delete these items?',
128+
'hard_delete_bulk_description' => 'This action will permanently delete these items.',
129+
'hard_delete_confirmation' => 'Are you sure you want to hard delete this item?',
130+
'hard_delete_description' => 'This action will permanently delete this item.',
131+
'empty_trash_confirmation' => 'Are you sure you want to empty the trash?',
132+
'empty_trash_description' => 'This action will permanently delete all items in the trash.',
122133
];

src/CoreServiceProvider.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ public function boot()
1919
{
2020
parent::boot();
2121

22-
// TODO: Uncomment this line to enable policies
23-
//$this->setPolicies();
24-
2522
if (config('core.use_google_icons', true)) {
2623
$this->useGoogleIcons();
2724
}
2825

26+
$this->loadTranslationsFrom(lang_path('previews'), 'previews');
27+
2928
$this->app->booted(function () {
3029
$this->translateConfigurations();
3130
});
@@ -55,14 +54,14 @@ protected function getPackageNames(): array
5554

5655
protected function translateConfigurations()
5756
{
58-
$packages = $this->getPackageNames();
57+
$configs = config()->all();
58+
$translatedConfigs = $this->translateConfig($configs);
5959

60-
foreach ($packages as $slug => $name) {
61-
$configData = config($slug);
62-
if (is_array($configData)) {
63-
$translatedConfig = $this->translateConfig($configData);
64-
config([$slug => $translatedConfig]);
60+
foreach ($translatedConfigs as $key => $value) {
61+
if ($key === 'app') {
62+
continue;
6563
}
64+
config([$key => $value]);
6665
}
6766
}
6867

src/Forms/TaxonomyCreateForm.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Moox\Core\Forms;
4+
5+
use Camya\Filament\Forms\Components\TitleWithSlugInput;
6+
7+
class TaxonomyCreateForm
8+
{
9+
public static function getSchema(): array
10+
{
11+
return [
12+
TitleWithSlugInput::make(
13+
fieldTitle: 'title',
14+
fieldSlug: 'slug',
15+
),
16+
];
17+
}
18+
}

src/Services/TabStateManager.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Moox\Core\Services;
6+
7+
class TabStateManager
8+
{
9+
protected static ?string $currentTab = null;
10+
11+
public static function getCurrentTab(): ?string
12+
{
13+
return request()->query('activeTab', '');
14+
}
15+
16+
public static function setCurrentTab(?string $tab): void
17+
{
18+
static::$currentTab = $tab;
19+
}
20+
}

src/Services/TaxonomyService.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
namespace Moox\Core\Services;
4+
5+
use Illuminate\Support\Facades\Config;
6+
7+
class TaxonomyService
8+
{
9+
private ?string $currentResource = null;
10+
11+
public function setCurrentResource(string $resource): void
12+
{
13+
$this->currentResource = $resource;
14+
}
15+
16+
public function getCurrentResource(): ?string
17+
{
18+
return $this->currentResource;
19+
}
20+
21+
private function ensureResourceIsSet(): void
22+
{
23+
if ($this->currentResource === null) {
24+
throw new \RuntimeException('Current resource is not set. Call setCurrentResource() first.');
25+
}
26+
}
27+
28+
public function getTaxonomies(): array
29+
{
30+
$this->ensureResourceIsSet();
31+
32+
return Config::get("previews.{$this->currentResource}.taxonomies", [])
33+
?: Config::get("builder.resources.{$this->currentResource}.taxonomies", []);
34+
}
35+
36+
public function getTaxonomyModel(string $taxonomy): ?string
37+
{
38+
return $this->getTaxonomies()[$taxonomy]['model'] ?? null;
39+
}
40+
41+
public function validateTaxonomy(string $taxonomy): void
42+
{
43+
$modelClass = $this->getTaxonomyModel($taxonomy);
44+
45+
if (! $modelClass || ! class_exists($modelClass)) {
46+
throw new \InvalidArgumentException("Invalid model class for taxonomy: $taxonomy in resource: {$this->currentResource}");
47+
}
48+
}
49+
50+
public function getTaxonomyRelationship(string $taxonomy): string
51+
{
52+
return $this->getTaxonomies()[$taxonomy]['relationship'] ?? 'taggable';
53+
}
54+
55+
public function getTaxonomyTable(string $taxonomy): string
56+
{
57+
return $this->getTaxonomies()[$taxonomy]['table'] ?? 'taggables';
58+
}
59+
60+
public function getTaxonomyForeignKey(string $taxonomy): string
61+
{
62+
return $this->getTaxonomies()[$taxonomy]['foreignKey'] ?? 'taggable_id';
63+
}
64+
65+
public function getTaxonomyRelatedKey(string $taxonomy): string
66+
{
67+
return $this->getTaxonomies()[$taxonomy]['relatedKey'] ?? 'tag_id';
68+
}
69+
70+
public function hasTaxonomies(): bool
71+
{
72+
$this->ensureResourceIsSet();
73+
74+
return ! empty($this->getTaxonomies());
75+
}
76+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Moox\Core\Traits\Base;
6+
7+
trait BaseInCreatePage
8+
{
9+
//
10+
}

src/Traits/Base/BaseInEditPage.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Moox\Core\Traits\Base;
6+
7+
trait BaseInEditPage
8+
{
9+
//
10+
}

0 commit comments

Comments
 (0)