Skip to content

Commit

Permalink
Merge pull request #17 from IBEC-BOX/fix/published-is-date-only
Browse files Browse the repository at this point in the history
Fix/published is date only
  • Loading branch information
ast21 authored Jul 24, 2024
2 parents fe99f88 + c93b12b commit f1309b5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 28 deletions.
4 changes: 4 additions & 0 deletions config/admin-kit-articles.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@
'seo' => [
'enabled' => true,
],

'published_at' => [
'with_time' => true,
],
];
66 changes: 38 additions & 28 deletions src/UI/Filament/Resources/ArticleResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use AdminKit\Core\Forms\Components\TranslatableTabs;
use AdminKit\SEO\Forms\Components\SEOComponent;
use Filament\Forms;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Forms\Set;
Expand All @@ -25,9 +27,9 @@ class ArticleResource extends Resource

public static function form(Form $form): Form
{
$rows = [];
$components = [];
if (config('admin-kit-articles.image.enabled')) {
$rows[] = Forms\Components\SpatieMediaLibraryFileUpload::make('image')
$components[] = Forms\Components\SpatieMediaLibraryFileUpload::make('image')
->label(__('admin-kit-articles::articles.resource.image'))
->image()
->required()
Expand All @@ -40,28 +42,11 @@ public static function form(Form $form): Form
->imagePreviewHeight(config('admin-kit-articles.image.preview_height'))

// cropper
->imageEditor();
->imageEditor()
->columnSpan(12);
}

$rows[] = Forms\Components\Grid::make(1)
->schema([
Forms\Components\TextInput::make('slug')
->label(__('admin-kit-articles::articles.resource.slug'))
->disabled(fn (Get $get) => ! $get('slug-editable'))
->required()
->unique(Article::class, 'slug', ignoreRecord: true)
->suffixAction(
Forms\Components\Actions\Action::make('slug-edit')
->icon(fn (Get $get) => $get('slug-editable') ? 'heroicon-o-lock-closed' : 'heroicon-s-pencil-square')
->action(function (Set $set, Get $get) {
$set('slug-editable', ! $get('slug-editable'));
})),
Forms\Components\Checkbox::make('slug-editable')
->default(false)
->hidden(),
]);

$rows[] = TranslatableTabs::make(fn ($locale) => [
$components[] = TranslatableTabs::make(fn ($locale) => [
Forms\Components\TextInput::make("title.$locale")
->label(__('admin-kit-articles::articles.resource.title'))
->required($locale === app()->getLocale())
Expand All @@ -83,24 +68,49 @@ function (string $context, string $state, Set $set, Get $get) use ($locale) {
->label(__('admin-kit-articles::articles.resource.short_content'))
->columnSpan(2),
])
->columnSpan(2)
->columnSpan([
12,
'lg' => 8,
])
->columns();

$rows[] = Forms\Components\Section::make([
Forms\Components\DateTimePicker::make('published_at')
$publishedAt = config('admin-kit-articles.published_at.with_time') ? DateTimePicker::class : DatePicker::class;

$components[] = Forms\Components\Section::make([
Forms\Components\TextInput::make('slug')
->label(__('admin-kit-articles::articles.resource.slug'))
->disabled(fn (Get $get) => ! $get('slug-editable'))
->required()
->unique(Article::class, 'slug', ignoreRecord: true)
->suffixAction(
Forms\Components\Actions\Action::make('slug-edit')
->icon(fn (Get $get) => $get('slug-editable') ? 'heroicon-o-lock-closed' : 'heroicon-s-pencil-square')
->action(function (Set $set, Get $get) {
$set('slug-editable', ! $get('slug-editable'));
}))
->columnSpan(2),
Forms\Components\Checkbox::make('slug-editable')
->default(false)
->hidden(),

$publishedAt::make('published_at')
->label(__('admin-kit-articles::articles.resource.published_date'))
->columnSpan(2),

Forms\Components\Toggle::make('pinned')
->label(__('admin-kit-articles::articles.resource.pinned'))
->columnSpan(2),
]);
])
->columnSpan([
12,
'lg' => 4,
])->columns();

if (config('admin-kit-articles.seo.enabled')) {
$rows[] = SEOComponent::make();
$components[] = SEOComponent::make();
}

return $form->schema($rows);
return $form->schema($components)->columns(12);
}

public static function table(Table $table): Table
Expand Down

0 comments on commit f1309b5

Please sign in to comment.