diff --git a/packages/core/database/migrations/2025_12_19_120000_add_published_at_empty_on_create_to_types_table.php b/packages/core/database/migrations/2025_12_19_120000_add_published_at_empty_on_create_to_types_table.php new file mode 100644 index 0000000..a1987a8 --- /dev/null +++ b/packages/core/database/migrations/2025_12_19_120000_add_published_at_empty_on_create_to_types_table.php @@ -0,0 +1,28 @@ +boolean('published_at_empty_on_create')->default(false)->after('parent_required'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('types', function (Blueprint $table) { + $table->dropColumn('published_at_empty_on_create'); + }); + } +}; diff --git a/packages/core/src/Models/Type.php b/packages/core/src/Models/Type.php index 0a21837..be4eab2 100644 --- a/packages/core/src/Models/Type.php +++ b/packages/core/src/Models/Type.php @@ -25,6 +25,7 @@ protected function casts(): array return [ 'og_image_fields' => 'array', 'parent_filters' => 'array', + 'published_at_empty_on_create' => 'boolean', 'default_meta_tags_robots' => 'array', ]; } diff --git a/packages/core/src/Resources/ContentResource.php b/packages/core/src/Resources/ContentResource.php index 0e9435d..833ed22 100644 --- a/packages/core/src/Resources/ContentResource.php +++ b/packages/core/src/Resources/ContentResource.php @@ -565,9 +565,43 @@ function (Set $set, $component) { DateTimePicker::make('published_at') ->columnSpanFull() ->date() - ->default(now()->format('dd/mm/YYYY')) + ->default(function (Get $get, ?Content $record) { + if ($record) { + return $record->published_at; + } + + $type = self::$type; + if (! $type) { + $type = Type::firstWhere('slug', ($get('type_slug') ?? $record?->type_slug)); + } + + if ($type && $type->published_at_empty_on_create) { + return null; + } + + return now(); + }) ->displayFormat('M j, Y - H:i') - ->formatStateUsing(fn (?Content $record) => $record ? $record->published_at : now()) + ->formatStateUsing(function (?Content $record, Get $get) { + if ($record && $record->published_at) { + return $record->published_at; + } + + if ($record) { + return null; + } + + $type = self::$type; + if (! $type) { + $type = Type::firstWhere('slug', $get('type_slug')); + } + + if ($type && $type->published_at_empty_on_create) { + return null; + } + + return now(); + }) ->label(__('Publication date')) ->helperText('Set a date in past or future to schedule publication.') ->native(false) diff --git a/packages/core/src/Resources/TypeResource.php b/packages/core/src/Resources/TypeResource.php index 3f2cb96..4f0dcab 100644 --- a/packages/core/src/Resources/TypeResource.php +++ b/packages/core/src/Resources/TypeResource.php @@ -157,6 +157,14 @@ public static function form(\Filament\Schemas\Schema $schema): \Filament\Schemas 'desc' => 'Descending', ]), ])->columns(2), + Fieldset::make(__('Publication')) + ->schema([ + Toggle::make('published_at_empty_on_create') + ->label(__('Published At Empty On Create')) + ->helperText(__('If enabled, published_at will be empty when creating new content. Publication date must be set manually.')) + ->inline(false) + ->columnSpanFull(), + ]), Fieldset::make(__('Meta Tags')) ->schema([ Select::make('default_meta_tags_robots') @@ -173,6 +181,7 @@ public static function form(\Filament\Schemas\Schema $schema): \Filament\Schemas ->helperText(__('If enabled, all content of this type must have a parent.')) ->live() ->inline(false), + Repeater::make('parent_filters') ->label(__('Filters')) ->live()