Skip to content

Commit 3998298

Browse files
committed
Merge branch 'main' of github.com:backstagephp/fields into feature/conditional-fields
2 parents f00a1f1 + b5576e3 commit 3998298

File tree

5 files changed

+87
-7
lines changed

5 files changed

+87
-7
lines changed

.github/workflows/fix-php-code-style-issues.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
ref: ${{ github.head_ref }}
2020

2121
- name: Fix PHP code style issues
22-
uses: aglipanci/laravel-pint-action@2.5
22+
uses: aglipanci/laravel-pint-action@2.6
2323

2424
- name: Commit changes
2525
uses: stefanzweifel/git-auto-commit-action@v6

src/Concerns/CanMapDynamicFields.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Backstage\Fields\Fields\Color;
1111
use Backstage\Fields\Fields\DateTime;
1212
use Backstage\Fields\Fields\KeyValue;
13+
use Backstage\Fields\Fields\MarkdownEditor;
1314
use Backstage\Fields\Fields\Radio;
1415
use Backstage\Fields\Fields\Repeater;
1516
use Backstage\Fields\Fields\RichEditor;
@@ -41,6 +42,7 @@ trait CanMapDynamicFields
4142
'text' => Text::class,
4243
'textarea' => Textarea::class,
4344
'rich-editor' => RichEditor::class,
45+
'markdown-editor' => MarkdownEditor::class,
4446
'repeater' => Repeater::class,
4547
'select' => Select::class,
4648
'checkbox' => Checkbox::class,

src/Enums/Field.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ enum Field: string
1212
case CheckboxList = 'checkbox-list';
1313
case Color = 'color';
1414
case DateTime = 'date-time';
15-
case File = 'file-upload';
16-
case Hidden = 'hidden';
15+
// case File = 'file-upload';
16+
// case Hidden = 'hidden';
1717
case KeyValue = 'key-value';
18-
case Link = 'link';
18+
// case Link = 'link';
1919
case MarkdownEditor = 'markdown-editor';
2020
case Radio = 'radio';
2121
case Repeater = 'repeater';
@@ -25,5 +25,5 @@ enum Field: string
2525
case Text = 'text';
2626
case Textarea = 'textarea';
2727
case Toggle = 'toggle';
28-
case ToggleButtons = 'toggle-buttons';
28+
// case ToggleButtons = 'toggle-buttons';
2929
}

src/Fields/MarkdownEditor.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
namespace Backstage\Fields\Fields;
4+
5+
use Backstage\Fields\Contracts\FieldContract;
6+
use Backstage\Fields\Enums\ToolbarButton;
7+
use Backstage\Fields\Models\Field;
8+
use Filament\Forms;
9+
use Filament\Forms\Components\RichEditor as Input;
10+
11+
class MarkdownEditor extends Base implements FieldContract
12+
{
13+
public static function getDefaultConfig(): array
14+
{
15+
return [
16+
...parent::getDefaultConfig(),
17+
'toolbarButtons' => ['attachFiles', 'blockquote', 'bold', 'bulletList', 'codeBlock', 'heading', 'italic', 'link', 'orderedList', 'redo', 'strike', 'table', 'undo'],
18+
'disableToolbarButtons' => [],
19+
'fileAttachmentsDisk' => 'public',
20+
'fileAttachmentsDirectory' => 'attachments',
21+
'fileAttachmentsVisibility' => 'public',
22+
];
23+
}
24+
25+
public static function make(string $name, ?Field $field = null): Input
26+
{
27+
$input = self::applyDefaultSettings(Input::make($name), $field);
28+
29+
$input = $input->label($field->name ?? null)
30+
->toolbarButtons($field->config['toolbarButtons'] ?? self::getDefaultConfig()['toolbarButtons'])
31+
->disableToolbarButtons($field->config['disableToolbarButtons'] ?? self::getDefaultConfig()['disableToolbarButtons'])
32+
->fileAttachmentsDisk($field->config['fileAttachmentsDisk'] ?? self::getDefaultConfig()['fileAttachmentsDisk'])
33+
->fileAttachmentsDirectory($field->config['fileAttachmentsDirectory'] ?? self::getDefaultConfig()['fileAttachmentsDirectory'])
34+
->fileAttachmentsVisibility($field->config['fileAttachmentsVisibility'] ?? self::getDefaultConfig()['fileAttachmentsVisibility']);
35+
36+
return $input;
37+
}
38+
39+
public function getForm(): array
40+
{
41+
return [
42+
Forms\Components\Tabs::make()
43+
->schema([
44+
Forms\Components\Tabs\Tab::make('General')
45+
->label(__('General'))
46+
->schema([
47+
...parent::getForm(),
48+
]),
49+
Forms\Components\Tabs\Tab::make('Field specific')
50+
->label(__('Field specific'))
51+
->schema([
52+
Forms\Components\Grid::make(2)
53+
->schema([
54+
Forms\Components\Select::make('config.toolbarButtons')
55+
->label(__('Toolbar buttons'))
56+
->default(['attachFiles', 'blockquote', 'bold', 'bulletList', 'codeBlock', 'heading', 'italic', 'link', 'orderedList', 'redo', 'strike', 'table', 'undo'])
57+
->default(ToolbarButton::array()) // Not working in Filament yet.
58+
->multiple()
59+
->options(ToolbarButton::array())
60+
->columnSpanFull(),
61+
Forms\Components\Grid::make(3)
62+
->schema([
63+
Forms\Components\TextInput::make('config.fileAttachmentsDisk')
64+
->label(__('File attachments disk'))
65+
->default('public'),
66+
Forms\Components\TextInput::make('config.fileAttachmentsDirectory')
67+
->label(__('File attachments directory'))
68+
->default('attachments'),
69+
Forms\Components\TextInput::make('config.fileAttachmentsVisibility')
70+
->label(__('File attachments visibility'))
71+
->default('public'),
72+
]),
73+
]),
74+
]),
75+
])->columnSpanFull(),
76+
];
77+
}
78+
}

src/Fields/Select.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static function make(string $name, ?Field $field = null): Input
8080
return $input;
8181
}
8282

83-
public static function mutateFormDataCallback(Model $record, $field, array $data): array
83+
public static function mutateFormDataCallback(Model $record, Field $field, array $data): array
8484
{
8585
if (! property_exists($record, 'valueColumn') || ! isset($record->values[$field->ulid])) {
8686
return $data;
@@ -92,7 +92,7 @@ public static function mutateFormDataCallback(Model $record, $field, array $data
9292
return $data;
9393
}
9494

95-
public static function mutateBeforeSaveCallback(Model $record, $field, array $data): array
95+
public static function mutateBeforeSaveCallback(Model $record, Field $field, array $data): array
9696
{
9797
if (! property_exists($record, 'valueColumn') || ! isset($data[$record->valueColumn][$field->ulid])) {
9898
return $data;

0 commit comments

Comments
 (0)