Skip to content

Commit 515fa92

Browse files
authored
fix(cmseditor): do not crash on invalid boolean values (#101)
1 parent 44229db commit 515fa92

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/Http/Controllers/CmsEditor/CmsEditorTemplateController.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ public function readOne(Template $table)
112112
$form->addInput((new LayoutInputText('params', 'Url parameters'))->setValue($table->params ?? ''));
113113
$form->addInput((new LayoutInputText('allow_children', "Subpagina's"))->setValue($table->allow_children ?? '')); // TODO: Make this a tableselect that gets the existing cms_templates
114114

115-
$form->addInput((new LayoutInputCheckbox('enabled', 'Active'))->setValue($table->enabled == 1 ?? false));
116-
$form->addInput((new LayoutInputCheckbox('meta', 'Add meta fields'))->setValue($table->properties->meta ?? false));
115+
$form->addInput((new LayoutInputCheckbox('enabled', 'Active'))->setValue($this->forceBool($table->enabled)));
116+
$form->addInput((new LayoutInputCheckbox('meta', 'Add meta fields'))->setValue($this->forceBool($table->properties->meta ?? false)));
117117

118-
$form->addInput((new LayoutInputCheckbox('searchable', 'Searchable via SOLR'))->setValue($table->properties->searchable ?? false));
118+
$form->addInput((new LayoutInputCheckbox('searchable', 'Searchable via SOLR'))->setValue($this->forceBool($table->properties->searchable ?? false)));
119119

120120
$form->addButton(new LayoutButton('Update template properties'));
121121
$widget1->addTitle((new LayoutTitle('Edit template'))->setSize(4));
@@ -159,7 +159,7 @@ public function readOne(Template $table)
159159
$row->addColumn(new LayoutTableColumn($cmsTable->name, 'text'));
160160
$row->addColumn(new LayoutTableColumn($cmsTable->type, 'text'));
161161
$row->addColumn(new LayoutTableColumn($cmsTable->internal, 'internal'));
162-
$row->addColumn(new LayoutTableColumn($cmsTable->enabled, 'checkbox'));
162+
// $row->addColumn(new LayoutTableColumn($cmsTable->enabled, 'checkbox'));
163163
$UItable->addRow($row);
164164
}
165165
$widget2->addTable($UItable);
@@ -256,4 +256,19 @@ public function updatePosition(HttpRequest $request, Template $table)
256256

257257
return response()->json(['status' => 'ok']);
258258
}
259+
260+
private function forceBool(mixed $value): bool
261+
{
262+
if (is_null($value)) {
263+
return false;
264+
}
265+
if (is_bool($value)) {
266+
return $value;
267+
}
268+
if ($value == 1) {
269+
return true;
270+
}
271+
272+
return false;
273+
}
259274
}

0 commit comments

Comments
 (0)