Skip to content

Commit

Permalink
feat: configurable short content
Browse files Browse the repository at this point in the history
  • Loading branch information
ast21 committed Jul 24, 2024
1 parent 674a020 commit adc9520
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
5 changes: 5 additions & 0 deletions config/admin-kit-articles.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@
'published_at' => [
'with_time' => true,
],

'short_content' => [
'enabled' => false,
'is_wysiwyg' => false,
],
];
20 changes: 16 additions & 4 deletions src/UI/Filament/Resources/ArticleResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Filament\Forms;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Forms\Set;
Expand Down Expand Up @@ -46,6 +48,18 @@ public static function form(Form $form): Form
->columnSpan(12);
}

$shortContent = function ($locale): array {
$shortContentClass = config('admin-kit-articles.short_content.is_wysiwyg') ? RichEditor::class : Textarea::class;

if (config('admin-kit-articles.short_content.enabled')) {
return [$shortContentClass::make("short_content.$locale")
->label(__('admin-kit-articles::articles.resource.short_content'))
->columnSpan(2)];
}

return [];
};

$components[] = TranslatableTabs::make(fn ($locale) => [
Forms\Components\TextInput::make("title.$locale")
->label(__('admin-kit-articles::articles.resource.title'))
Expand All @@ -59,14 +73,12 @@ function (string $context, string $state, Set $set, Get $get) use ($locale) {
})
->columnSpan(2),

Forms\Components\RichEditor::make("content.$locale")
RichEditor::make("content.$locale")
->label(__('admin-kit-articles::articles.resource.content'))
->required($locale === app()->getLocale())
->columnSpan(2),

Forms\Components\RichEditor::make("short_content.$locale")
->label(__('admin-kit-articles::articles.resource.short_content'))
->columnSpan(2),
...$shortContent($locale),
])
->columnSpan([
12,
Expand Down

0 comments on commit adc9520

Please sign in to comment.