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
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('types', function (Blueprint $table) {
$table->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');
});
}
};
1 change: 1 addition & 0 deletions packages/core/src/Models/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
}
Expand Down
38 changes: 36 additions & 2 deletions packages/core/src/Resources/ContentResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/Resources/TypeResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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()
Expand Down