Skip to content
Open
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
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@
"datalinx/php-utils": "^2.5",
"eclipsephp/common": "dev-main",
"filament/filament": "^3.3",
"spatie/laravel-package-tools": "^1.19"
"filament/spatie-laravel-translatable-plugin": "^3.3",
"solution-forest/filament-tree": "^2.1",
"spatie/laravel-package-tools": "^1.19",
"spatie/laravel-translatable": "^6.11"
},
"require-dev": {
"laravel/pint": "^1.21",
Expand Down
59 changes: 47 additions & 12 deletions database/factories/PageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,67 @@

namespace Eclipse\Cms\Factories;

use Eclipse\Cms\Enums\PageStatus;
use Eclipse\Cms\Models\Page;
use Eclipse\Cms\Models\Section;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon;

/**
* @experimental
*/
class PageFactory extends Factory
{
protected $model = Page::class;

public function definition(): array
{
$englishTitle = $this->faker->sentence(3);
$slovenianTitle = "SI: {$englishTitle}";

$englishShortText = $this->faker->text(200);
$slovenianShortText = "SI: {$englishShortText}";

$englishLongText = $this->faker->text(500);
$slovenianLongText = "SI: {$englishLongText}";

$slug = $this->faker->slug();

return [
'title' => $this->faker->word(),
'short_text' => $this->faker->text(),
'long_text' => $this->faker->text(),
'sef_key' => $this->faker->word(),
'code' => $this->faker->word(),
'status' => $this->faker->word(),
'type' => $this->faker->word(),
'title' => [
'en' => $englishTitle,
'sl' => $slovenianTitle,
],
'short_text' => [
'en' => $englishShortText,
'sl' => $slovenianShortText,
],
'long_text' => [
'en' => $englishLongText,
'sl' => $slovenianLongText,
],
'sef_key' => [
'en' => $slug,
'sl' => "{$slug}-si",
],
'code' => $this->faker->unique()->word(),
'status' => $this->faker->randomElement([PageStatus::Draft, PageStatus::Published]),
'type' => 'page',
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),

'section_id' => Section::factory(),
];
}

public function configure()
{
return $this->afterMaking(function (Page $page) {
if (! $page->section_id) {
$page->section_id = Section::factory()->create()->id;
}
});
}

public function forSection($section): static
{
return $this->state([
'section_id' => $section->id,
]);
}
}
43 changes: 35 additions & 8 deletions database/factories/SectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Eclipse\Cms\Enums\SectionType;
use Eclipse\Cms\Models\Section;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Arr;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;

Expand All @@ -15,18 +14,46 @@ class SectionFactory extends Factory

public function definition(): array
{
$attrs = [
'name' => Str::of($this->faker->words(asText: true))->ucwords(),
'type' => $this->faker->randomElement(Arr::pluck(SectionType::cases(), 'name')),
$englishName = Str::of($this->faker->words(asText: true))->ucwords();
$slovenianName = "SI: {$englishName}";

return [
'name' => [
'en' => $englishName,
'sl' => $slovenianName,
],
'type' => $this->faker->randomElement(SectionType::cases()),
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
];
}

public function configure()
{
return $this->afterMaking(function (Section $section) {
if (config('eclipse-cms.tenancy.enabled')) {
$foreignKey = config('eclipse-cms.tenancy.foreign_key');
$currentValue = $section->getAttribute($foreignKey);

if (config('eclipse-cms.tenancy.enabled') && empty($attrs[config('eclipse-cms.tenancy.foreign_key')])) {
$class = config('eclipse-cms.tenancy.model');
$attrs[config('eclipse-cms.tenancy.foreign_key')] = $class::inRandomOrder()->first()?->id ?? $class::factory()->create()->id;
if (! $currentValue || $currentValue === null) {
$class = config('eclipse-cms.tenancy.model');
if (class_exists($class)) {
$newValue = $class::inRandomOrder()->first()?->id ?? $class::factory()->create()->id;
$section->setAttribute($foreignKey, $newValue);
}
}
}
});
}

public function forSite($site): static
{
if (config('eclipse-cms.tenancy.enabled')) {
return $this->state([
config('eclipse-cms.tenancy.foreign_key') => $site->id,
]);
}

return $attrs;
return $this;
}
}
10 changes: 9 additions & 1 deletion database/seeders/CmsSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@

namespace Eclipse\Cms\Seeders;

use Eclipse\Cms\Models\Page;
use Eclipse\Cms\Models\Section;
use Illuminate\Database\Seeder;

class CmsSeeder extends Seeder
{
public function run(): void
{
Section::factory()
$sections = Section::factory()
->count(3)
->create();

$sections->each(function (Section $section): void {
Page::factory()
->count(3)
->forSection($section)
->create();
});
}
}
Loading
Loading