Skip to content

Commit 4ed6769

Browse files
committed
Merge remote-tracking branch 'origin/9.0' into 9.0
2 parents 130fa67 + 9162a40 commit 4ed6769

File tree

9 files changed

+82
-52
lines changed

9 files changed

+82
-52
lines changed

demo/app/Sharp/Categories/CategoryForm.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ public function buildFormFields(FieldsContainer $formFields): void
3434

3535
public function buildFormLayout(FormLayout $formLayout): void
3636
{
37-
$formLayout->addColumn(6, function (FormLayoutColumn $column) {
38-
$column->withField('name')
39-
->withField('description');
40-
});
37+
$formLayout
38+
->addColumn(6, fn (FormLayoutColumn $column) => $column
39+
->withField('name')
40+
->withField('description')
41+
);
4142
}
4243

4344
public function buildFormConfig(): void

demo/app/Sharp/Posts/PostForm.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
use Code16\Sharp\Form\Layout\FormLayoutTab;
2828
use Code16\Sharp\Form\SharpForm;
2929
use Code16\Sharp\Utils\Fields\FieldsContainer;
30-
use Code16\Sharp\Utils\PageAlerts\PageAlert;
3130

3231
class PostForm extends SharpForm
3332
{
@@ -191,7 +190,7 @@ public function buildFormLayout(FormLayout $formLayout): void
191190
});
192191
});
193192
}
194-
193+
195194
public function buildFormConfig(): void
196195
{
197196
$this->configureDisplayShowPageAfterCreation()

docs/guide/quick-creation-form.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Quick creation form
22

3-
Sometimes you may want to allow the creation of a new instance directly from the list page, without having to navigate to a dedicated creation page. It's especially useful when the create form does not require a lot of fields, to keep the user in the list context — and since Sharp will display a "submit and reopen" button in the modal, the user can quickly create multiple instances.
3+
Sometimes you may want to allow the creation of a new instance directly from the list page, without having to navigate to a dedicated creation form. It's especially useful when the create form does not require a lot of fields, to keep the user in the list context — and since Sharp will display a “Create and create another” button in the modal, the user can quickly create many instances.
44

55
## Prerequisites
66

@@ -36,6 +36,10 @@ class MyList extends SharpEntityList
3636

3737
Of course, ensure that these fields are defined in the Form and that all the required fields are present.
3838

39+
::: warning
40+
The quick creation form is designed for simple forms. In particular, the layout is entirely ignored, as fields are simply placed one below another. If your form contains many fields or require a specific layout, it is better to use the regular creation form.
41+
:::
42+
3943
## Redirect to the Show Page
4044

4145
When the Form is configured with `configureDisplayShowPageAfterCreation()`, and if the user does not choose to stay in creation (with the "submit and reopen" button), Sharp will redirect to the Show Page after the creation.

docs/guide/upgrading/9.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ This means you also need to remove all `$this->initSharpAssertions()` calls from
398398

399399
Of course, the test helpers remain available, see the dedicated [testing documentation](../testing-with-sharp.md).
400400

401+
Also take note that the `withSharpCurrentBreadcrumb()` method is now deprecated, in favor of the new `withSharpBreadcrumb()` method also documented in the section linked above.
402+
401403
# Dashboard
402404

403405
## `SharpWidgetPanel`s are now based on blade template

src/EntityList/Commands/QuickCreate/QuickCreationCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function getDataLocalizations(): array
6464
{
6565
return $this->sharpForm->getDataLocalizations();
6666
}
67-
67+
6868
public function getInstanceId(): mixed
6969
{
7070
return $this->instanceId;

src/Form/Layout/HasModalFormLayout.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Code16\Sharp\Form\Layout;
44

5+
use Code16\Sharp\Form\Fields\SharpFormField;
6+
use Code16\Sharp\Form\Fields\SharpFormListField;
57
use Code16\Sharp\Utils\Fields\HandleFields;
68

79
/**
@@ -21,8 +23,17 @@ protected function modalFormLayout(\Closure $buildFormLayout): ?array
2123
$buildFormLayout($column);
2224

2325
if (! $column->hasFields()) {
26+
// Handle default layout
2427
collect($fields)
25-
->each(fn ($field) => $column->withField($field->key()));
28+
->each(fn (SharpFormField $field) => $field instanceof SharpFormListField
29+
? $column->withListField($field->key, fn ($layout) => $field
30+
->itemFields()
31+
->each(fn (SharpFormField $itemField) => $layout
32+
->withSingleField($itemField->key())
33+
)
34+
)
35+
: $column->withField($field->key)
36+
);
2637
}
2738
})
2839
->toArray();

tests/Http/Api/Commands/ApiEntityListEntityCommandControllerTest.php

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use Code16\Sharp\EntityList\Commands\EntityCommand;
44
use Code16\Sharp\Exceptions\Form\SharpApplicativeException;
5+
use Code16\Sharp\Form\Fields\SharpFormListField;
56
use Code16\Sharp\Form\Fields\SharpFormTextField;
67
use Code16\Sharp\Tests\Fixtures\Entities\PersonEntity;
78
use Code16\Sharp\Tests\Fixtures\Sharp\PersonList;
@@ -487,7 +488,14 @@ public function label(): ?string
487488

488489
public function buildFormFields(FieldsContainer $formFields): void
489490
{
490-
$formFields->addField(SharpFormTextField::make('name'));
491+
$formFields
492+
->addField(SharpFormTextField::make('name'))
493+
->addField(
494+
SharpFormListField::make('jobs')
495+
->addItemField(
496+
SharpFormTextField::make('company')
497+
)
498+
);
491499
}
492500

493501
public function execute(array $data = []): array
@@ -503,13 +511,6 @@ public function execute(array $data = []): array
503511
->getJson(route('code16.sharp.api.list.command.entity.form', ['person', 'cmd']))
504512
->assertOk()
505513
->assertJsonFragment([
506-
'fields' => [
507-
'name' => [
508-
'key' => 'name',
509-
'type' => 'text',
510-
'inputType' => 'text',
511-
],
512-
],
513514
'layout' => [
514515
'tabbed' => false,
515516
'tabs' => [
@@ -518,7 +519,24 @@ public function execute(array $data = []): array
518519
[
519520
'fields' => [
520521
[
521-
['key' => 'name', 'size' => 12],
522+
[
523+
'key' => 'name',
524+
'size' => 12,
525+
],
526+
],
527+
[
528+
[
529+
'key' => 'jobs',
530+
'size' => 12,
531+
'item' => [
532+
[
533+
[
534+
'key' => 'company',
535+
'size' => 12,
536+
],
537+
],
538+
],
539+
],
522540
],
523541
],
524542
'size' => 12,

tests/Unit/Utils/Testing/SharpAssertionsTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,35 @@
171171
);
172172
});
173173

174+
it('allows to test getSharpForm for edit with a custom breadcrumb with legacy API', function () {
175+
$response = fakeResponse()
176+
->withSharpCurrentBreadcrumb(
177+
['list', 'leaves'],
178+
['show', 'leaves', 6],
179+
)
180+
->getSharpForm('leaves', 6);
181+
182+
$this->assertEquals(
183+
route('code16.sharp.form.edit', ['s-list/leaves/s-show/leaves/6', 'leaves', 6]),
184+
$response->uri,
185+
);
186+
});
187+
188+
it('allows to define a current breadcrumb with legacy API', function () {
189+
$response = fakeResponse()
190+
->withSharpCurrentBreadcrumb(
191+
['list', 'trees'],
192+
['show', 'trees', 2],
193+
['show', 'leaves', 6],
194+
)
195+
->getSharpForm('leaves', 6);
196+
197+
$this->assertEquals(
198+
'http://localhost/sharp/s-list/trees/s-show/trees/2/s-show/leaves/6/s-form/leaves/6',
199+
$response->uri,
200+
);
201+
});
202+
174203
function fakeResponse()
175204
{
176205
return new class('fake') extends Orchestra\Testbench\TestCase

tests/Unit/Utils/Testing/SharpLegacyAssertionsTest.php

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

0 commit comments

Comments
 (0)