Skip to content

Commit e96cfc7

Browse files
committed
Merge branch 'main' of github.com:backstagephp/cms into 2.x
2 parents 3a21def + ff77869 commit e96cfc7

File tree

7 files changed

+155
-18
lines changed

7 files changed

+155
-18
lines changed

database/migrations/create_language_rules_tables.php.stub

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,40 @@ return new class extends Migration
88
{
99
public function up()
1010
{
11-
Schema::create('language_rules', function (Blueprint $table) {
12-
$table->id();
11+
if (Schema::hasTable('language_rules') && Schema::hasTable('language_rules_conditions')) {
12+
return;
13+
}
1314

14-
$table->string('code', 5);
15+
if (! Schema::hasTable('language_rules')) {
16+
Schema::create('language_rules', function (Blueprint $table) {
17+
$table->id();
1518

16-
$table->string('name');
19+
$table->string('code', 5);
1720

18-
$table->longText('global_instructions')->nullable();
21+
$table->string('name');
1922

20-
$table->timestamps();
21-
$table->softDeletes();
22-
});
23+
$table->longText('global_instructions')->nullable();
2324

24-
Schema::create('language_rules_conditions', function (Blueprint $table) {
25-
$table->id();
25+
$table->timestamps();
26+
$table->softDeletes();
27+
});
28+
}
2629

27-
$table->foreignId('language_rule_id')->constrained('language_rules');
30+
if (! Schema::hasTable('language_rules_conditions')) {
31+
Schema::create('language_rules_conditions', function (Blueprint $table) {
32+
$table->id();
2833

29-
$table->string('key');
34+
$table->foreignId('language_rule_id')->constrained('language_rules');
3035

31-
$table->string('type'); // must, must_not
36+
$table->string('key');
3237

33-
$table->json('value');
38+
$table->string('type'); // must, must_not
3439

35-
$table->timestamps();
36-
});
40+
$table->json('value');
41+
42+
$table->timestamps();
43+
});
44+
}
3745
}
3846

3947
public function down()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
public function up(): void
10+
{
11+
Schema::table('types', function (Blueprint $table) {
12+
$table->json('default_meta_tags_robots')->nullable()->after('og_image_fields');
13+
});
14+
}
15+
16+
public function down(): void
17+
{
18+
Schema::table('types', function (Blueprint $table) {
19+
$table->dropColumn('default_meta_tags_robots');
20+
});
21+
}
22+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('types', function (Blueprint $table) {
15+
$table->boolean('published_at_empty_on_create')->default(false)->after('parent_required');
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('types', function (Blueprint $table) {
25+
$table->dropColumn('published_at_empty_on_create');
26+
});
27+
}
28+
};

packages/core/src/Models/Type.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ protected function casts(): array
2525
return [
2626
'og_image_fields' => 'array',
2727
'parent_filters' => 'array',
28+
'published_at_empty_on_create' => 'boolean',
29+
'default_meta_tags_robots' => 'array',
2830
];
2931
}
3032

packages/core/src/Resources/ContentResource.php

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,21 @@ public static function form(Schema $schema): Schema
291291
->label(__('Robots'))
292292
->options(['noindex' => __('Do not index this content (noindex)'), 'nofollow' => __('Do not follow links (nofollow)'), 'noarchive' => __('Do not archive this content (noarchive)'), 'nosnippet' => __('No description in search results (nosnippet)'), 'noodp' => __('Do not index this in Open Directory Project (noodp)')])
293293
->multiple()
294+
->default(function (?Content $record, Get $get) {
295+
if ($record && isset($record->meta_tags['robots']) && ! empty($record->meta_tags['robots'])) {
296+
return $record->meta_tags['robots'];
297+
}
298+
299+
$type = self::$type;
300+
if (! $type) {
301+
$typeSlug = $get('type_slug') ?? $record?->type_slug;
302+
if ($typeSlug) {
303+
$type = Type::firstWhere('slug', $typeSlug);
304+
}
305+
}
306+
307+
return $type?->default_meta_tags_robots;
308+
})
294309
->columnSpanFull(),
295310

296311
TagsInput::make('meta_tags.keywords')
@@ -550,9 +565,43 @@ function (Set $set, $component) {
550565
DateTimePicker::make('published_at')
551566
->columnSpanFull()
552567
->date()
553-
->default(now()->format('dd/mm/YYYY'))
568+
->default(function (Get $get, ?Content $record) {
569+
if ($record) {
570+
return $record->published_at;
571+
}
572+
573+
$type = self::$type;
574+
if (! $type) {
575+
$type = Type::firstWhere('slug', ($get('type_slug') ?? $record?->type_slug));
576+
}
577+
578+
if ($type && $type->published_at_empty_on_create) {
579+
return null;
580+
}
581+
582+
return now();
583+
})
554584
->displayFormat('M j, Y - H:i')
555-
->formatStateUsing(fn (?Content $record) => $record ? $record->published_at : now())
585+
->formatStateUsing(function (?Content $record, Get $get) {
586+
if ($record && $record->published_at) {
587+
return $record->published_at;
588+
}
589+
590+
if ($record) {
591+
return null;
592+
}
593+
594+
$type = self::$type;
595+
if (! $type) {
596+
$type = Type::firstWhere('slug', $get('type_slug'));
597+
}
598+
599+
if ($type && $type->published_at_empty_on_create) {
600+
return null;
601+
}
602+
603+
return now();
604+
})
556605
->label(__('Publication date'))
557606
->helperText('Set a date in past or future to schedule publication.')
558607
->native(false)

packages/core/src/Resources/ContentResource/Pages/EditContent.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Backstage\Models\Content;
99
use Backstage\Models\Language;
1010
use Backstage\Models\Tag;
11+
use Backstage\Models\Type;
1112
use Backstage\Resources\ContentResource;
1213
use Backstage\Translations\Laravel\Facades\Translator;
1314
use Filament\Actions\Action;
@@ -216,6 +217,14 @@ protected function mutateFormDataBeforeFill(array $data): array
216217

217218
$this->getRecord()->values = $values;
218219

220+
// Backwards compatibility: if meta_tags.robots is not set, use type default
221+
if (! isset($data['meta_tags']['robots']) || empty($data['meta_tags']['robots'])) {
222+
$type = $this->getRecord()->type;
223+
if ($type && $type->default_meta_tags_robots) {
224+
$data['meta_tags']['robots'] = $type->default_meta_tags_robots;
225+
}
226+
}
227+
219228
return $this->mutateBeforeFill($data);
220229
}
221230

packages/core/src/Resources/TypeResource.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,31 @@ public static function form(\Filament\Schemas\Schema $schema): \Filament\Schemas
157157
'desc' => 'Descending',
158158
]),
159159
])->columns(2),
160+
Fieldset::make(__('Publication'))
161+
->schema([
162+
Toggle::make('published_at_empty_on_create')
163+
->label(__('Published At Empty On Create'))
164+
->helperText(__('If enabled, published_at will be empty when creating new content. Publication date must be set manually.'))
165+
->inline(false)
166+
->columnSpanFull(),
167+
]),
168+
Fieldset::make(__('Meta Tags'))
169+
->schema([
170+
Select::make('default_meta_tags_robots')
171+
->label(__('Default Robots'))
172+
->options(['noindex' => __('Do not index this content (noindex)'), 'nofollow' => __('Do not follow links (nofollow)'), 'noarchive' => __('Do not archive this content (noarchive)'), 'nosnippet' => __('No description in search results (nosnippet)'), 'noodp' => __('Do not index this in Open Directory Project (noodp)')])
173+
->multiple()
174+
->helperText(__('Default robots settings for new content of this type. Can be overridden per content item.'))
175+
->columnSpanFull(),
176+
]),
160177
Fieldset::make(__('Parent selection'))
161178
->schema([
162179
Toggle::make('parent_required')
163180
->label(__('Parent Required'))
164181
->helperText(__('If enabled, all content of this type must have a parent.'))
165182
->live()
166183
->inline(false),
184+
167185
Repeater::make('parent_filters')
168186
->label(__('Filters'))
169187
->live()
@@ -214,6 +232,7 @@ public static function form(\Filament\Schemas\Schema $schema): \Filament\Schemas
214232
])
215233
->columnSpanFull(),
216234
]),
235+
217236
]),
218237
Tab::make(__('Info'))
219238
->schema([

0 commit comments

Comments
 (0)