Skip to content

Commit

Permalink
fix(admin): Add fallback layout for form group properties
Browse files Browse the repository at this point in the history
If no layout is defined, create a layout of single columns matching the number of properties to render.
  • Loading branch information
mcaskill committed Mar 11, 2024
1 parent 2e0c6a7 commit 04169c8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/admin/src/Charcoal/Admin/Widget/DocWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,16 @@ public function formProperties(array $group = null)
$props = array_merge($group, $props);
}

if (!$this->layout()) {
// Ensure a layout is present and matches the number
// of properties to be rendered.
$this->setLayout([
'structure' => [
[ 'columns' => [ 1 ], 'loop' => count($props) ],
],
]);
}

foreach ($props as $propertyIdent => $propertyMetadata) {
$propertyIdent = $this->camelize($propertyIdent);
if (method_exists($obj, 'filterPropertyMetadata')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,16 @@ public function formProperties()
$propPreferences = $this->propertiesOptions();
$structProperties = $this->parsedFormProperties();

if (!$this->layout()) {
// Ensure a layout is present and matches the number
// of properties to be rendered.
$this->setLayout([
'structure' => [
[ 'columns' => [ 1 ], 'loop' => count($structProperties) ],
],
]);
}

foreach ($structProperties as $propertyIdent => $propertyMetadata) {
if (is_array($propertyMetadata)) {
$propertyMetadata['ident'] = $propertyIdent;
Expand Down
11 changes: 10 additions & 1 deletion packages/admin/src/Charcoal/Admin/Widget/FormGroupWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ public function propertiesOptions()
return $this->propertiesOptions;
}


/**
* Determine if the form group has properties.
*
Expand All @@ -187,6 +186,16 @@ public function formProperties()
$formProperties = $this->parsedFormProperties();
$propOptions = $this->propertiesOptions();

if (!$this->layout()) {
// Ensure a layout is present and matches the number
// of properties to be rendered.
$this->setLayout([
'structure' => [
[ 'columns' => [ 1 ], 'loop' => count($groupProperties) ],
],
]);
}

foreach ($formProperties as $propertyIdent => $formProperty) {
$propertyIdent = $this->camelize($propertyIdent);
if (in_array($propertyIdent, $groupProperties)) {
Expand Down

0 comments on commit 04169c8

Please sign in to comment.