Skip to content

Commit 30e6fa4

Browse files
Migrate to Sharp9
1 parent 7423ba1 commit 30e6fa4

15 files changed

+131
-166
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"email": "antoine@code16.fr"
1010
}],
1111
"require": {
12-
"php": "^8.0|^8.1|^8.2|^8.3",
13-
"laravel/framework": "^8.0|^9.0|^10.0|^11.0",
12+
"php": "^8.2|^8.3|^8.4",
13+
"laravel/framework": "^^10.0|^11.0",
1414
"nesbot/carbon": "^2.0",
1515
"maatwebsite/excel": "^3.1",
1616
"ext-zip": "*"
@@ -21,7 +21,7 @@
2121
"phpunit/phpunit": "^10.0",
2222
"doctrine/dbal": "^3.0",
2323
"orchestra/testbench": "6.*|7.*|8.*|9.*",
24-
"code16/sharp": "^8.0",
24+
"code16/sharp": "^9.0",
2525
"ext-json": "*"
2626
},
2727
"autoload": {

src/Sharp/FormojAnswerSharpEntityList.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Code16\Formoj\Sharp\Commands\FormojAnswerExportCommand;
77
use Code16\Sharp\EntityList\Fields\EntityListField;
88
use Code16\Sharp\EntityList\Fields\EntityListFieldsContainer;
9-
use Code16\Sharp\EntityList\Fields\EntityListFieldsLayout;
9+
use Code16\Sharp\EntityList\Filters\HiddenFilter;
1010
use Code16\Sharp\EntityList\SharpEntityList;
1111
use Illuminate\Contracts\Support\Arrayable;
1212

@@ -19,27 +19,24 @@ public function buildList(EntityListFieldsContainer $fields): void
1919
->addField(
2020
EntityListField::make("created_at")
2121
->setLabel(trans("formoj::sharp.answers.list.columns.created_at_label"))
22-
->setWidth(3)
23-
->setWidthOnSmallScreensFill()
2422
)
2523
->addField(
2624
EntityListField::make("content")
2725
->setLabel(trans("formoj::sharp.answers.list.columns.content_label"))
28-
->setWidth(9)
29-
->setWidthOnSmallScreensFill()
3026
);
3127
}
3228

33-
function buildListConfig(): void
29+
function getEntityCommands(): ?array
3430
{
35-
$this
36-
->configurePaginated();
31+
return [
32+
FormojAnswerExportCommand::class
33+
];
3734
}
3835

39-
function getEntityCommands(): ?array
36+
protected function getFilters(): ?array
4037
{
4138
return [
42-
FormojAnswerExportCommand::class
39+
HiddenFilter::make('formoj_form')
4340
];
4441
}
4542

src/Sharp/FormojAnswerSharpShow.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
class FormojAnswerSharpShow extends SharpShow
1717
{
18-
1918
protected function buildShowFields(FieldsContainer $showFields): void
2019
{
2120
$showFields
@@ -26,21 +25,11 @@ protected function buildShowFields(FieldsContainer $showFields): void
2625
// This field IS NOT displayed, and is used to handle the custom file DL in the FormojReplySharpEntityList list
2726
->addField(
2827
SharpShowFileField::make("file")
29-
->setStorageDisk(config("formoj.storage.disk"))
30-
->setStorageBasePath(
31-
sprintf(
32-
"%s/%s/answers/{id}",
33-
config("formoj.storage.path"),
34-
currentSharpRequest()->getPreviousShowFromBreadcrumbItems("formoj_form")->instanceId()
35-
)
36-
)
3728
)
3829
->addField(
3930
SharpShowEntityListField::make("replies", "formoj_reply")
4031
->setLabel(trans("formoj::sharp.answers.fields.replies.label"))
41-
->hideFilterWithValue("formoj_answer", function($instanceId) {
42-
return $instanceId;
43-
})
32+
->hideFilterWithValue("formoj_answer", fn($id) => $id)
4433
);
4534
}
4635

@@ -51,7 +40,7 @@ protected function buildShowLayout(ShowLayout $showLayout): void
5140
$section
5241
->addColumn(6, function(ShowLayoutColumn $column) {
5342
$column
54-
->withSingleField("created_at");
43+
->withField("created_at");
5544
});
5645
})
5746
->addEntityListSection("replies");

src/Sharp/FormojFieldSharpEntityList.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
namespace Code16\Formoj\Sharp;
44

55
use Code16\Formoj\Models\Field;
6-
use Code16\Formoj\Sharp\Reorder\FormojFieldReorderHandler;
76
use Code16\Sharp\EntityList\Eloquent\SimpleEloquentReorderHandler;
87
use Code16\Sharp\EntityList\Fields\EntityListField;
98
use Code16\Sharp\EntityList\Fields\EntityListFieldsContainer;
9+
use Code16\Sharp\EntityList\Filters\HiddenFilter;
1010
use Code16\Sharp\EntityList\SharpEntityList;
1111
use Illuminate\Contracts\Support\Arrayable;
1212

@@ -18,19 +18,14 @@ public function buildList(EntityListFieldsContainer $fields): void
1818
->addField(
1919
EntityListField::make("type")
2020
->setLabel(trans("formoj::sharp.fields.list.columns.type_label"))
21-
->setWidth(3)
22-
->setWidthOnSmallScreensFill()
2321
)
2422
->addField(
2523
EntityListField::make("label")
2624
->setLabel(trans("formoj::sharp.fields.list.columns.label_label"))
27-
->setWidth(5)
28-
->setWidthOnSmallScreensFill()
2925
)
3026
->addField(
3127
EntityListField::make("help_text")
3228
->setLabel(trans("formoj::sharp.fields.list.columns.help_text_label"))
33-
->setWidth(4)
3429
->hideOnSmallScreens()
3530
);
3631
}
@@ -42,6 +37,13 @@ function buildListConfig(): void
4237
);
4338
}
4439

40+
protected function getFilters(): ?array
41+
{
42+
return [
43+
HiddenFilter::make('formoj_section')
44+
];
45+
}
46+
4547
public function getListData(): array|Arrayable
4648
{
4749
$fields = Field::orderBy("order")

src/Sharp/FormojFieldSharpForm.php

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Code16\Formoj\Sharp;
44

55
use Code16\Formoj\Models\Field;
6+
use Code16\Formoj\Models\Section;
67
use Code16\Sharp\Form\Eloquent\WithSharpFormEloquentUpdater;
78
use Code16\Sharp\Form\Fields\SharpFormCheckField;
89
use Code16\Sharp\Form\Fields\SharpFormListField;
@@ -14,12 +15,11 @@
1415
use Code16\Sharp\Form\Layout\FormLayoutFieldset;
1516
use Code16\Sharp\Form\SharpForm;
1617
use Code16\Sharp\Utils\Fields\FieldsContainer;
18+
use Illuminate\Validation\Rule;
1719

1820
class FormojFieldSharpForm extends SharpForm
1921
{
2022
use WithSharpFormEloquentUpdater;
21-
22-
protected ?string $formValidatorClass = FormojFieldSharpValidator::class;
2323

2424
function buildFormFields(FieldsContainer $formFields) : void
2525
{
@@ -125,27 +125,28 @@ function buildFormLayout(FormLayout $formLayout): void
125125
->addColumn(6, function (FormLayoutColumn $column) {
126126
$column
127127
->withFieldset(trans("formoj::sharp.fields.fields.fieldsets.identifiers"), function (FormLayoutFieldset $fieldset) {
128-
$fieldset->withSingleField("label")
129-
->withSingleField("identifier");
128+
$fieldset
129+
->withField("label")
130+
->withField("identifier");
130131
})
131-
->withSingleField("type")
132-
->withSingleField("required")
133-
->withSingleField("help_text");
132+
->withField("type")
133+
->withField("required")
134+
->withField("help_text");
134135

135136
})
136137
->addColumn(6, function (FormLayoutColumn $column) {
137138
$column
138-
->withSingleField("max_size")
139-
->withSingleField("accept")
140-
->withSingleField("max_length")
141-
->withSingleField("rows_count")
142-
->withSingleField("options", function(FormLayoutColumn $column) {
143-
$column->withSingleField("label");
139+
->withField("max_size")
140+
->withField("accept")
141+
->withField("max_length")
142+
->withField("rows_count")
143+
->withListField("options", function(FormLayoutColumn $column) {
144+
$column->withField("label");
144145
})
145-
->withSingleField("radios")
146-
->withSingleField("multiple")
147-
->withSingleField("lowest_label")
148-
->withSingleField("highest_label");
146+
->withField("radios")
147+
->withField("multiple")
148+
->withField("lowest_label")
149+
->withField("highest_label");
149150
});
150151
}
151152

@@ -177,7 +178,7 @@ function update($id, array $data)
177178
$field = $id
178179
? Field::findOrFail($id)
179180
: new Field([
180-
"section_id" => currentSharpRequest()->getPreviousShowFromBreadcrumbItems()->instanceId(),
181+
"section_id" => sharp()->context()->breadcrumb()->previousShowSegment()->instanceId(),
181182
"order" => 100
182183
]);
183184

@@ -238,4 +239,38 @@ protected function castValue(?string $value, string $type)
238239

239240
return $value;
240241
}
242+
243+
public function rules()
244+
{
245+
return [
246+
'label' => [
247+
'required',
248+
'max:200'
249+
],
250+
'identifier' => [
251+
'required',
252+
'max:100',
253+
'alpha_dash',
254+
Rule::unique('formoj_fields', 'identifier')
255+
->whereIn("section_id",
256+
Section::select("id")
257+
->where("form_id",
258+
Section::find(sharp()->context()->breadcrumb()->previousShowSegment()->instanceId())
259+
->form_id
260+
)
261+
->pluck("id")
262+
->all()
263+
)
264+
->ignore(sharp()->context()->instanceId())
265+
],
266+
'type' => 'required',
267+
'max_length' => 'integer|nullable',
268+
'max_values' => 'integer|nullable',
269+
'rows_count' => 'integer|nullable|required_if:type,' . Field::TYPE_TEXTAREA,
270+
'options' => 'required_if:type,' . Field::TYPE_SELECT,
271+
'options.*.label' => 'required',
272+
'max_size' => 'required_if:type,' . Field::TYPE_UPLOAD . '|integer|nullable',
273+
'accept' => ['nullable','regex:/^(\.[a-z]+,)*(\.[a-z]+)$/']
274+
];
275+
}
241276
}

src/Sharp/FormojFieldSharpValidator.php

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/Sharp/FormojFormSharpEntityList.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,27 @@ public function buildList(EntityListFieldsContainer $fields): void
2727
EntityListField::make("title")
2828
->setLabel(trans("formoj::sharp.forms.list.columns.title_label"))
2929
->setSortable()
30-
->setWidth(3)
31-
->setWidthOnSmallScreensFill()
3230
)
3331
->addField(
3432
EntityListField::make("description")
3533
->setLabel(trans("formoj::sharp.forms.list.columns.description_label"))
36-
->setWidth(3)
3734
->hideOnSmallScreens()
3835
)
3936
->addField(
4037
EntityListField::make("published_at")
4138
->setLabel(trans("formoj::sharp.forms.list.columns.published_at_label"))
4239
->setSortable()
43-
->setWidth(2)
44-
->setWidthOnSmallScreensFill()
4540
)
4641
->addField(
4742
EntityListField::make("sections")
4843
->setLabel(trans("formoj::sharp.forms.list.columns.sections_label"))
49-
->setWidth(3)
5044
->hideOnSmallScreens()
5145
);
5246
}
5347

5448
function buildListConfig(): void
5549
{
5650
$this
57-
->configurePaginated()
5851
->configureDefaultSort("ref", "desc")
5952
->configureSearchable();
6053
}

0 commit comments

Comments
 (0)