|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Usamamuneerchaudhary\Commentify\Filament\Pages; |
|
4
|
|
|
|
|
5
|
|
|
use Filament\Forms; |
|
|
|
|
|
|
6
|
|
|
use Filament\Forms\Concerns\InteractsWithForms; |
|
|
|
|
|
|
7
|
|
|
use Filament\Forms\Contracts\HasForms; |
|
|
|
|
|
|
8
|
|
|
use Filament\Forms\Form; |
|
|
|
|
|
|
9
|
|
|
use Filament\Notifications\Notification; |
|
|
|
|
|
|
10
|
|
|
use Filament\Pages\Page; |
|
|
|
|
|
|
11
|
|
|
use Filament\Schemas\Components\Section; |
|
|
|
|
|
|
12
|
|
|
use Filament\Schemas\Schema; |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
class CommentifySettings extends Page implements HasForms |
|
15
|
|
|
{ |
|
16
|
|
|
use InteractsWithForms; |
|
17
|
|
|
|
|
18
|
|
|
protected static string|null|\BackedEnum $navigationIcon = 'heroicon-o-cog-6-tooth'; |
|
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
protected static string|null|\UnitEnum $navigationGroup = 'Commentify'; |
|
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
protected static ?int $navigationSort = 10; |
|
24
|
|
|
|
|
25
|
|
|
public ?array $data = []; |
|
26
|
|
|
|
|
27
|
|
|
public static function getNavigationLabel(): string |
|
28
|
|
|
{ |
|
29
|
|
|
return 'Commentify Settings'; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function getView(): string |
|
33
|
|
|
{ |
|
34
|
|
|
return 'commentify::pages.settings'; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function form(Schema $schema): Schema |
|
38
|
|
|
{ |
|
39
|
|
|
return $schema |
|
40
|
|
|
->schema([ |
|
41
|
|
|
Section::make('General Settings') |
|
42
|
|
|
->schema([ |
|
43
|
|
|
Forms\Components\Select::make('css_framework') |
|
|
|
|
|
|
44
|
|
|
->label('CSS Framework') |
|
45
|
|
|
->options([ |
|
46
|
|
|
'tailwind' => 'Tailwind CSS', |
|
47
|
|
|
'bootstrap' => 'Bootstrap', |
|
48
|
|
|
]) |
|
49
|
|
|
->default('tailwind') |
|
50
|
|
|
->required() |
|
51
|
|
|
->helperText('Choose the CSS framework for comment components'), |
|
52
|
|
|
Forms\Components\TextInput::make('users_route_prefix') |
|
|
|
|
|
|
53
|
|
|
->label('Users Route Prefix') |
|
54
|
|
|
->default('users') |
|
55
|
|
|
->required(), |
|
56
|
|
|
Forms\Components\TextInput::make('pagination_count') |
|
57
|
|
|
->label('Comments Per Page') |
|
58
|
|
|
->numeric() |
|
59
|
|
|
->default(10) |
|
60
|
|
|
->required(), |
|
61
|
|
|
Forms\Components\Toggle::make('comment_nesting') |
|
|
|
|
|
|
62
|
|
|
->label('Enable Comment Nesting') |
|
63
|
|
|
->default(true), |
|
64
|
|
|
Forms\Components\Toggle::make('read_only') |
|
65
|
|
|
->label('Read Only Mode') |
|
66
|
|
|
->helperText('Disable all commenting functionality') |
|
67
|
|
|
->default(false), |
|
68
|
|
|
]), |
|
69
|
|
|
Section::make('Sorting & Display') |
|
70
|
|
|
->schema([ |
|
71
|
|
|
Forms\Components\Select::make('default_sort') |
|
72
|
|
|
->label('Default Sort Order') |
|
73
|
|
|
->options([ |
|
74
|
|
|
'newest' => 'Newest First', |
|
75
|
|
|
'oldest' => 'Oldest First', |
|
76
|
|
|
'most_liked' => 'Most Liked', |
|
77
|
|
|
'most_replied' => 'Most Replied', |
|
78
|
|
|
]) |
|
79
|
|
|
->default('newest') |
|
80
|
|
|
->required(), |
|
81
|
|
|
Forms\Components\Toggle::make('enable_sorting') |
|
82
|
|
|
->label('Enable Sorting') |
|
83
|
|
|
->default(true), |
|
84
|
|
|
]), |
|
85
|
|
|
Section::make('Moderation') |
|
86
|
|
|
->schema([ |
|
87
|
|
|
Forms\Components\Toggle::make('enable_reporting') |
|
88
|
|
|
->label('Enable Comment Reporting') |
|
89
|
|
|
->default(true), |
|
90
|
|
|
Forms\Components\TagsInput::make('report_reasons') |
|
|
|
|
|
|
91
|
|
|
->label('Report Reasons') |
|
92
|
|
|
->placeholder('Add report reason') |
|
93
|
|
|
->default(['spam', 'inappropriate', 'offensive', 'other']), |
|
94
|
|
|
]), |
|
95
|
|
|
Section::make('Features') |
|
96
|
|
|
->schema([ |
|
97
|
|
|
Forms\Components\Select::make('theme') |
|
98
|
|
|
->label('Theme Mode') |
|
99
|
|
|
->options([ |
|
100
|
|
|
'light' => 'Light', |
|
101
|
|
|
'dark' => 'Dark', |
|
102
|
|
|
'auto' => 'Auto (System Preference)', |
|
103
|
|
|
]) |
|
104
|
|
|
->default('auto') |
|
105
|
|
|
->required(), |
|
106
|
|
|
Forms\Components\Toggle::make('enable_emoji_picker') |
|
107
|
|
|
->label('Enable Emoji Picker') |
|
108
|
|
|
->default(true), |
|
109
|
|
|
]), |
|
110
|
|
|
Section::make('Notifications') |
|
111
|
|
|
->schema([ |
|
112
|
|
|
Forms\Components\Toggle::make('enable_notifications') |
|
113
|
|
|
->label('Enable Notifications') |
|
114
|
|
|
->default(false), |
|
115
|
|
|
Forms\Components\CheckboxList::make('notification_channels') |
|
|
|
|
|
|
116
|
|
|
->label('Notification Channels') |
|
117
|
|
|
->options([ |
|
118
|
|
|
'database' => 'Database', |
|
119
|
|
|
'mail' => 'Email', |
|
120
|
|
|
'broadcast' => 'Broadcast (WebSocket)', |
|
121
|
|
|
]) |
|
122
|
|
|
->default(['database']) |
|
123
|
|
|
->visible(fn ($get) => $get('enable_notifications')), |
|
124
|
|
|
]), |
|
125
|
|
|
]) |
|
126
|
|
|
->statePath('data'); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public function mount(): void |
|
130
|
|
|
{ |
|
131
|
|
|
$this->form->fill(config('commentify', [])); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
public function save(): void |
|
135
|
|
|
{ |
|
136
|
|
|
$data = $this->form->getState(); |
|
137
|
|
|
|
|
138
|
|
|
// Save to config file |
|
139
|
|
|
$configPath = config_path('commentify.php'); |
|
140
|
|
|
|
|
141
|
|
|
if (file_exists($configPath)) { |
|
142
|
|
|
$config = require $configPath; |
|
143
|
|
|
$config = array_merge($config, $data); |
|
144
|
|
|
|
|
145
|
|
|
file_put_contents( |
|
146
|
|
|
$configPath, |
|
147
|
|
|
"<?php\n\nreturn " . var_export($config, true) . ";\n" |
|
148
|
|
|
); |
|
149
|
|
|
|
|
150
|
|
|
// Clear config cache |
|
151
|
|
|
if (function_exists('config')) { |
|
152
|
|
|
app()->make('config')->set('commentify', $config); |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
Notification::make() |
|
157
|
|
|
->title('Settings saved successfully') |
|
158
|
|
|
->success() |
|
159
|
|
|
->send(); |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths