julienmonnerie/kirby/config/sections/fields.php

63 lines
1.2 KiB
PHP
Raw Normal View History

2022-06-17 17:51:59 +02:00
<?php
2022-12-19 14:56:05 +01:00
use Kirby\Cms\Page;
use Kirby\Cms\Site;
2022-06-17 17:51:59 +02:00
use Kirby\Form\Form;
return [
2022-08-31 15:02:43 +02:00
'props' => [
'fields' => function (array $fields = []) {
return $fields;
}
],
'computed' => [
'form' => function () {
$fields = $this->fields;
$disabled = $this->model->permissions()->update() === false;
$lang = $this->model->kirby()->languageCode();
$content = $this->model->content($lang)->toArray();
2022-06-17 17:51:59 +02:00
2022-08-31 15:02:43 +02:00
if ($disabled === true) {
foreach ($fields as $key => $props) {
$fields[$key]['disabled'] = true;
}
}
2022-06-17 17:51:59 +02:00
2022-08-31 15:02:43 +02:00
return new Form([
'fields' => $fields,
'values' => $content,
'model' => $this->model,
'strict' => true
]);
},
'fields' => function () {
$fields = $this->form->fields()->toArray();
2022-06-17 17:51:59 +02:00
2022-12-19 14:56:05 +01:00
if (
$this->model instanceof Page ||
$this->model instanceof Site
) {
2022-08-31 15:02:43 +02:00
// the title should never be updated directly via
// fields section to avoid conflicts with the rename dialog
unset($fields['title']);
}
2022-06-17 17:51:59 +02:00
2022-08-31 15:02:43 +02:00
foreach ($fields as $index => $props) {
unset($fields[$index]['value']);
}
2022-06-17 17:51:59 +02:00
2022-08-31 15:02:43 +02:00
return $fields;
}
],
'methods' => [
'errors' => function () {
return $this->form->errors();
}
],
'toArray' => function () {
return [
'fields' => $this->fields,
];
}
2022-06-17 17:51:59 +02:00
];