Skip to content

Commit 6b1722a

Browse files
committed
minor #5932 Rename Form Panels as Form Fieldsets (javiereguiluz)
This PR was squashed before being merged into the 4.x branch. Discussion ---------- Rename Form Panels as Form Fieldsets I know that renames are always annoying because you need to change things in your apps for something that doesn't provide anything valuable 🙏 But: **(1)** If you don't change anything, everything should keep working the same. You won't see any change ... except some new messages in the list of deprecations shown by Symfony **(2)** To fix those deprecations, you can use your IDE/editor to do this: ```diff -::addPanel('...') +::addFieldset('...') ``` **(3)** Only people doing very obscure/advanced things will need to do some more `panel` -> `fieldset` renames. ----- Why do I propose this? Because fieldsets is a much more natural word for this feature and also, because it feels better with some upcoming changes in a nice feature that I will unveil in the future. Commits ------- fa98932 Rename Form Panels as Form Fieldsets
2 parents 8fc96c6 + fa98932 commit 6b1722a

22 files changed

+351
-326
lines changed

UPGRADE.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
Upgrade between EasyAdmin 4.x versions
22
======================================
33

4+
EasyAdmin 4.8.0
5+
---------------
6+
7+
### Form Panels are now called Form Fieldsets
8+
9+
You can still use `FormField::addPanel()` but it's deprecated and it will be
10+
removed in EasyAdmin 5.0.0. To fix the deprecation, "Find & Replace" in your IDE:
11+
12+
// Before
13+
yield FormField::addPanel('...');
14+
15+
// After
16+
yield FormField::addFieldset('...');
17+
18+
If your application uses custom advanced features, you might need to change some
19+
other occurrences of "panel" such as CSS styles (`.form-panel` -> `.form-fieldset`)
20+
and form attributes in `CrudFormType` (`$formFieldOptions['ea_form_panel']` ->
21+
`$formFieldOptions['ea_form_fieldset'] = $currentFormFieldset`)
22+
423
EasyAdmin 4.6.0
524
---------------
625

assets/css/easyadmin-theme/forms.scss

Lines changed: 13 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -344,108 +344,41 @@ label.form-check-label {
344344
margin-bottom: 15px;
345345
}
346346

347-
// Form fieldsets (used for the "from groups" feature)
348-
fieldset {
349-
background: var(--fieldset-bg);
350-
border: var(--border-width) var(--border-style) var(--border-color);
351-
border-radius: var(--border-radius);
352-
margin: 10px 0;
353-
padding: 10px 20px 15px;
354-
}
355-
356-
fieldset > legend {
357-
border: 0;
358-
font-size: var(--font-size-sm);
359-
font-weight: 500;
360-
text-transform: uppercase;
361-
margin: 0 0 5px -5px;
362-
padding: 0 5px;
363-
width: auto;
364-
}
365-
fieldset > legend .fa {
366-
color: var(--text-muted);
367-
font-size: var(--font-size-lg);
368-
margin-right: 4px;
369-
}
370-
371-
fieldset .form-section {
372-
padding-left: 0;
373-
padding-right: 0;
374-
}
375-
376-
fieldset .form-group {
377-
padding: 10px 0;
378-
}
379-
380-
fieldset .form-group label,
381-
fieldset .form-group legend.col-form-label {
382-
flex: 100% 0 0;
383-
margin: 0 0 4px 0;
384-
text-align: left;
385-
}
386-
387-
fieldset .form-group .form-widget,
388-
fieldset .field-checkbox .form-widget {
389-
flex: 0 0 100%;
390-
padding-left: 0;
391-
padding-right: 0;
392-
}
393-
394-
fieldset .field-checkbox .form-widget,
395-
fieldset .form-group.field-collection-action {
396-
margin-left: 0;
397-
}
398-
399-
fieldset .form-group.field-collection-action {
400-
padding-top: 0;
401-
}
402-
403-
fieldset .field-collection-action .btn {
404-
margin-left: 0;
405-
}
406-
407-
fieldset .legend-help {
408-
color: var(--text-muted);
409-
font-size: var(--font-size-sm);
410-
margin-bottom: 15px;
411-
margin-top: -5px;
412-
}
413-
414347
// Form sections
415-
.form-panel {
348+
.form-fieldset {
416349
padding: 0 0 20px;
417350
}
418351

419352
.form-section-empty {
420353
padding: 25px 10px 25px;
421354
}
422355

423-
.form-panel-header {
356+
.form-fieldset-header {
424357
align-items: flex-start;
425-
box-shadow: 0 1px 0 var(--form-panel-header-border-color);
358+
box-shadow: 0 1px 0 var(--form-fieldset-header-border-color);
426359
display: flex;
427360
flex-wrap: nowrap;
428361
padding: 15px 0 10px;
429362
position: relative;
430363

431-
.form-panel-collapse-marker {
432-
color: var(--form-panel-collapse-marker-color);
364+
.form-fieldset-collapse-marker {
365+
color: var(--form-fieldset-collapse-marker-color);
433366
margin: 0 10px 0 2px;
434367
transform: rotate(90deg);
435368
transition: transform .2s ease-in-out;
436369
}
437370

438-
.form-panel-title {
371+
.form-fieldset-title {
439372
flex: 1;
440373

441374
a {
442-
color: var(--form-panel-header-color);
375+
color: var(--form-fieldset-header-color);
443376
font-size: 20px;
444377
font-weight: bold;
445378

446379
&.not-collapsible { cursor: default; }
447380
&.collapsed {
448-
.form-panel-collapse-marker {
381+
.form-fieldset-collapse-marker {
449382
transform: rotate(0deg);
450383
}
451384
}
@@ -460,18 +393,18 @@ fieldset .legend-help {
460393
}
461394
}
462395

463-
.form-panel-icon {
464-
color: var(--form-panel-icon-color);
396+
.form-fieldset-icon {
397+
color: var(--form-fieldset-icon-color);
465398
margin-right: 5px;
466399
}
467400

468-
.form-panel-help {
469-
color: var(--form-panel-help-color);
401+
.form-fieldset-help {
402+
color: var(--form-fieldset-help-color);
470403
}
471404
}
472405
}
473406

474-
.form-panel-body {
407+
.form-fieldset-body {
475408
padding-top: 5px;
476409
}
477410

assets/css/easyadmin-theme/variables-theme.scss

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,11 @@
179179
--form-help-error-color: var(--gray-800);
180180
--form-help-active-color: var(--gray-800);
181181
--form-tabs-border-color: var(--gray-200);
182-
--form-panel-header-color: var(--gray-800);
183-
--form-panel-help-color: var(--gray-600);
184-
--form-panel-header-border-color: var(--gray-400);
185-
--form-panel-icon-color: var(--gray-500);
186-
--form-panel-collapse-marker-color: var(--gray-400);
182+
--form-fieldset-header-color: var(--gray-800);
183+
--form-fieldset-help-color: var(--gray-600);
184+
--form-fieldset-header-border-color: var(--gray-400);
185+
--form-fieldset-icon-color: var(--gray-500);
186+
--form-fieldset-collapse-marker-color: var(--gray-400);
187187
--form-collection-item-collapse-marker-color: var(--gray-400);
188188
--badge-border: 0;
189189
--badge-boolean-false-bg: var(--gray-200);
@@ -496,11 +496,11 @@
496496
--form-help-error-color: var(--true-gray-200);
497497
--form-help-active-color: var(--true-gray-300);
498498
--form-tabs-border-color: var(--true-gray-200);
499-
--form-panel-header-color: var(--true-gray-300);
500-
--form-panel-help-color: var(--true-gray-500);
501-
--form-panel-header-border-color: var(--true-gray-600);
502-
--form-panel-icon-color: var(--true-gray-500);
503-
--form-panel-collapse-marker-color: var(--true-gray-400);
499+
--form-fieldset-header-color: var(--true-gray-300);
500+
--form-fieldset-help-color: var(--true-gray-500);
501+
--form-fieldset-header-border-color: var(--true-gray-600);
502+
--form-fieldset-icon-color: var(--true-gray-500);
503+
--form-fieldset-collapse-marker-color: var(--true-gray-400);
504504
--form-collection-item-collapse-marker-color: var(--true-gray-400);
505505
--badge-box-shadow: inset 0 0 0 1px rgba(245, 245, 245, 0.3);
506506
--badge-boolean-false-bg: rgba(245, 245, 245, 0.1);

doc/fields.rst

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -344,38 +344,43 @@ force the creation of a new line (the next field will forcibly render on a new r
344344
];
345345
}
346346

347-
Form Panels
348-
~~~~~~~~~~~
347+
Form Fieldsets
348+
~~~~~~~~~~~~~~
349+
350+
.. versionadded:: 4.8.0
351+
352+
Form fieldsets were introduced in EasyAdmin 4.8.0. In previous versions,
353+
this feature was called "Form Panels".
349354

350355
In pages where you display lots of fields, you can divide them in groups using
351-
the "panels" created with the special ``FormField`` object::
356+
the fieldsets created with the special ``FormField`` object::
352357

353358
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
354359

355360
public function configureFields(string $pageName): iterable
356361
{
357362
return [
358-
// panels usually display only a title
359-
FormField::addPanel('User Details'),
363+
// fielfsets usually display only a title
364+
FormField::addFieldset('User Details'),
360365
TextField::new('firstName'),
361366
TextField::new('lastName'),
362367

363-
// panels without titles only display a separation between fields
364-
FormField::addPanel(),
368+
// fieldsets without titles only display a separation between fields
369+
FormField::addFieldset(),
365370
DateTimeField::new('createdAt')->onlyOnDetail(),
366371

367-
// panels can also define their icon, CSS class and help message
368-
FormField::addPanel('Contact information')
372+
// fieldsets can also define their icon, CSS class and help message
373+
FormField::addFieldset('Contact information')
369374
->setIcon('phone')->addCssClass('optional')
370375
->setHelp('Phone number is preferred'),
371376
TextField::new('phone'),
372377
TextField::new('email')->hideOnIndex(),
373378

374-
// panels can be collapsible too (useful if your forms are long)
375-
// this makes the panel collapsible but renders it expanded by default
376-
FormField::addPanel('Contact information')->collapsible(),
377-
// this makes the panel collapsible and renders it collapsed by default
378-
FormField::addPanel('Contact information')->renderCollapsed(),
379+
// fieldsets can be collapsible too (useful if your forms are long)
380+
// this makes the fieldset collapsible but renders it expanded by default
381+
FormField::addFieldset('Contact information')->collapsible(),
382+
// this makes the fieldset collapsible and renders it collapsed by default
383+
FormField::addFieldset('Contact information')->renderCollapsed(),
379384
];
380385
}
381386

@@ -395,8 +400,8 @@ the "tabs" created with the special ``FormField`` object::
395400
// Add a tab
396401
FormField::addTab('First Tab'),
397402

398-
// You can use a Form Panel inside a Form Tab
399-
FormField::addPanel('User Details'),
403+
// You can use a form fieldset inside a Form Tab
404+
FormField::addFieldset('User Details'),
400405

401406
// Your fields
402407
TextField::new('firstName'),

src/Dto/FieldDto.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
66
use EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore;
7-
use function Symfony\Component\String\u;
7+
use EasyCorp\Bundle\EasyAdminBundle\Form\Type\EaFormFieldsetType;
8+
use EasyCorp\Bundle\EasyAdminBundle\Form\Type\EasyAdminTabType;
89
use Symfony\Component\Uid\Ulid;
910
use Symfony\Contracts\Translation\TranslatableInterface;
1011

@@ -80,7 +81,17 @@ public function setUniqueId(string $uniqueId): void
8081

8182
public function isFormDecorationField(): bool
8283
{
83-
return u($this->getCssClass())->containsAny(['field-form_panel', 'field-form_tab']);
84+
return $this->isFormTab() || $this->isFormFieldset();
85+
}
86+
87+
public function isFormFieldset(): bool
88+
{
89+
return EaFormFieldsetType::class === $this->formType;
90+
}
91+
92+
public function isFormTab(): bool
93+
{
94+
return EasyAdminTabType::class === $this->formType;
8495
}
8596

8697
public function getFieldFqcn(): ?string

src/Factory/FieldFactory.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
2121
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
2222
use EasyCorp\Bundle\EasyAdminBundle\Field\TimeField;
23+
use EasyCorp\Bundle\EasyAdminBundle\Form\Type\EaFormFieldsetType;
2324
use EasyCorp\Bundle\EasyAdminBundle\Form\Type\EaFormRowType;
2425
use EasyCorp\Bundle\EasyAdminBundle\Form\Type\EasyAdminTabType;
2526
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
@@ -135,16 +136,7 @@ private function preProcessFields(FieldCollection $fields, EntityDto $entityDto)
135136
return;
136137
}
137138

138-
// this is needed to handle this edge-case: the list of fields include one or more form panels,
139-
// but the first fields of the list don't belong to any panel. We must create an automatic empty
140-
// form panel for those "orphaned fields" so they are displayed as expected
141-
$firstFieldIsAFormPanel = $fields->first()->isFormDecorationField();
142-
foreach ($fields as $fieldDto) {
143-
if (!$firstFieldIsAFormPanel && $fieldDto->isFormDecorationField()) {
144-
$fields->prepend(FormField::addPanel()->getAsDto());
145-
break;
146-
}
147-
}
139+
$this->fixOrphanFieldsetFields($fields);
148140

149141
foreach ($fields as $fieldDto) {
150142
if (Field::class !== $fieldDto->getFieldFqcn()) {
@@ -269,4 +261,26 @@ private function checkOrphanTabFields(FieldCollection $fields, AdminContext $con
269261

270262
throw new \RuntimeException(sprintf('The "%s" page of "%s" uses tabs to display its fields, but the following fields don\'t belong to any tab: %s. Use "FormField::addTab(\'...\')" to add a tab before those fields.', $context->getCrud()->getCurrentPage(), $context->getCrud()->getControllerFqcn(), implode(', ', $orphanFieldNames)));
271263
}
264+
265+
/*
266+
* This is needed to handle this edge-case: the list of fields include one or more form fieldsets,
267+
* but the first fields of the list don't belong to any fieldset. We must create an automatic empty
268+
* form fieldset for those "orphaned fields" so they are displayed as expected.
269+
*/
270+
private function fixOrphanFieldsetFields(FieldCollection $fields): void
271+
{
272+
$formUsesFieldsets = false;
273+
/** @var FieldDto $fieldDto */
274+
foreach ($fields as $fieldDto) {
275+
if (EaFormFieldsetType::class === $fieldDto->getFormType()) {
276+
$formUsesFieldsets = true;
277+
break;
278+
}
279+
}
280+
281+
$firstFieldIsAFieldsetOrTab = $fields->first()?->isFormDecorationField();
282+
if ($formUsesFieldsets && !$firstFieldIsAFieldsetOrTab) {
283+
$fields->prepend(FormField::addFieldset()->getAsDto());
284+
}
285+
}
272286
}

src/Field/Configurator/CommonPostConfigurator.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldConfiguratorInterface;
88
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
99
use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
10-
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
1110
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
1211
use function Symfony\Component\String\u;
1312
use Twig\Markup;

0 commit comments

Comments
 (0)