Edit shared headers and footers as page types
This commit is contained in:
@@ -10,6 +10,7 @@ use App\Content\CanvasStyle;
|
||||
use App\Content\DesignLibrary;
|
||||
use App\Content\Database;
|
||||
use App\Content\Html;
|
||||
use App\Content\LayoutPage;
|
||||
use App\Content\Passwords;
|
||||
use App\Content\Repository;
|
||||
use App\Content\SiteDesign;
|
||||
@@ -251,6 +252,10 @@ class AdminController
|
||||
if (!$page) {
|
||||
return $this->error($request, '找不到此页面。', 404);
|
||||
}
|
||||
$site = $repo->site();
|
||||
$layoutKind = $page['layout_kind'];
|
||||
$layout = $layoutKind === null ? null : DesignLibrary::find($page['layout_id'], $layoutKind);
|
||||
$default = $layout && ($site[$layoutKind . '_id'] ?? null) === $layout['id'];
|
||||
$error = '';
|
||||
if ($request->method() === 'POST') {
|
||||
$data = [];
|
||||
@@ -258,7 +263,10 @@ class AdminController
|
||||
$data[$field] = $this->input($request, $field);
|
||||
}
|
||||
$data['name'] = $request->post('name') === null ? $page['name'] : $this->input($request, 'name');
|
||||
$data['status'] = $request->post('status') === null || $slug === 'home' ? $page['status'] : $this->input($request, 'status');
|
||||
if ($layout) {
|
||||
$data['title'] = $data['name'];
|
||||
}
|
||||
$data['status'] = $layout || $request->post('status') === null || $slug === 'home' ? $page['status'] : $this->input($request, 'status');
|
||||
$scale = $this->input($request, 'image_scale');
|
||||
$data['image_scale'] = $request->post('image_scale') === null ? (int) $page['image_scale']
|
||||
: (ctype_digit($scale) ? (int) $scale : -1);
|
||||
@@ -282,6 +290,28 @@ class AdminController
|
||||
}
|
||||
$data['visibility'][$area] = $value === '1';
|
||||
}
|
||||
if ($layout) {
|
||||
$default = $request->post('make_default') === '1';
|
||||
$provider = null;
|
||||
if ($layoutKind === 'header' && $request->post('provider_mode') !== null) {
|
||||
foreach (DesignLibrary::PROVIDER_FIELDS as $name) {
|
||||
$provider[$name] = $this->input($request, 'provider_' . $name);
|
||||
}
|
||||
}
|
||||
$data['layoutConfig'] = ['default' => $default, 'provider' => $provider, 'secret' => $this->input($request, 'provider_secret', trimValue: false)];
|
||||
} else {
|
||||
foreach (['header', 'footer'] as $area) {
|
||||
$choice = $request->post($area . '_choice');
|
||||
if ($choice === null) {
|
||||
continue;
|
||||
}
|
||||
$data['visibility'][$area] = $choice !== 'hidden';
|
||||
if ($choice !== 'hidden') {
|
||||
$data[$area . '_id'] = DesignLibrary::selection($area, $choice);
|
||||
}
|
||||
}
|
||||
$page = array_replace($page, array_intersect_key($data, ['header_id' => true, 'footer_id' => true]));
|
||||
}
|
||||
$page['visibility'] = $data['visibility'];
|
||||
$data['alignments'] = $request->post('alignments') === null ? $page['alignments']
|
||||
: $this->alignmentMap(json_decode($this->input($request, 'alignments'), true), ['heading', 'lead', 'actions', 'image']);
|
||||
@@ -292,7 +322,7 @@ class AdminController
|
||||
$data['quicklinks'] = $request->post('quicklinks') === null ? $page['quicklinks'] : SiteDesign::parseLinks($this->input($request, 'quicklinks'));
|
||||
if ($data['name'] === '' || mb_strlen($data['name']) > 100 || !in_array($data['status'], ['draft', 'published'], true)
|
||||
|| $data['title'] === '' || mb_strlen($data['title']) > 160 ||
|
||||
($data['status'] === 'published' && $data['description'] === '') || mb_strlen($data['description']) > 300 ||
|
||||
(!$layout && $data['status'] === 'published' && $data['description'] === '') || mb_strlen($data['description']) > 300 ||
|
||||
(($data['visibility']['hero'] ?? true) && $data['heading'] === '') || mb_strlen($data['heading'] . $data['accent']) > 110 ||
|
||||
mb_strlen($data['lead']) > 600 || mb_strlen($data['alt']) > 200 ||
|
||||
($data['image_scale'] !== 0 && ($data['image_scale'] < 10 || $data['image_scale'] > 100)) ||
|
||||
@@ -318,8 +348,9 @@ class AdminController
|
||||
|
||||
return $this->render($request, 'admin-page', [
|
||||
'title' => '编辑 ' . $page['name'], 'page' => $page, 'categories' => $repo->categories(), 'wideAdmin' => true, 'error' => $error, 'saved' => $request->get('saved') === '1',
|
||||
'pageTemplateDrawer' => true, 'designs' => DesignLibrary::all(),
|
||||
'layoutDefaults' => array_intersect_key($repo->site(), ['header_id' => true, 'footer_id' => true]),
|
||||
'pageTemplateDrawer' => !$layout, 'designs' => DesignLibrary::all(), 'layout' => $layout, 'layoutDefault' => $default,
|
||||
'layoutHasMember' => $layoutKind === 'header' && LayoutPage::hasMember($page['sections']),
|
||||
'layoutDefaults' => array_intersect_key($site, ['header_id' => true, 'footer_id' => true]),
|
||||
], $error !== '' ? 422 : 200);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user