Edit shared headers and footers as page types
This commit is contained in:
@@ -5,7 +5,9 @@ declare(strict_types=1);
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Content\BlockTemplates;
|
||||
use App\Content\DesignLibrary;
|
||||
use App\Content\Html;
|
||||
use App\Content\LayoutPage;
|
||||
use App\Content\Media;
|
||||
use App\Content\PageDraft;
|
||||
use App\Content\PageTemplates;
|
||||
@@ -22,16 +24,26 @@ final class StudioController extends AdminController
|
||||
if ($failure = $this->guard($request)) {
|
||||
return $failure;
|
||||
}
|
||||
$type = $request->get('type');
|
||||
$data = [
|
||||
'title' => '新建页面', 'name' => '', 'slug' => '', 'error' => '', 'pageTemplateDrawer' => true,
|
||||
'openTemplates' => $request->get('templates') === '1',
|
||||
'type' => is_string($type) && isset(LayoutPage::TYPES[$type]) ? $type : 'page',
|
||||
];
|
||||
if ($request->method() === 'POST') {
|
||||
$data['name'] = $this->input($request, 'name');
|
||||
$data['slug'] = $this->input($request, 'slug');
|
||||
$data['type'] = $request->post('type') === null ? 'page' : $this->input($request, 'type');
|
||||
try {
|
||||
if (!$this->slug($data['slug']) || in_array($data['slug'], PageDraft::RESERVED, true)
|
||||
|| $data['name'] === '' || mb_strlen($data['name']) > 100) {
|
||||
if (!isset(LayoutPage::TYPES[$data['type']]) || $data['name'] === '' || mb_strlen($data['name']) > 100) {
|
||||
throw new RuntimeException('请填写页面名称并选择页面类型。');
|
||||
}
|
||||
if ($data['type'] !== 'page') {
|
||||
$slug = LayoutPage::create($data['type'], $data['name']);
|
||||
|
||||
return $this->success($request, '/admin/pages/' . $slug);
|
||||
}
|
||||
if (!$this->slug($data['slug']) || in_array($data['slug'], PageDraft::RESERVED, true)) {
|
||||
throw new RuntimeException('请填写页面名称及可用的网址标识。');
|
||||
}
|
||||
$key = $this->input($request, 'template');
|
||||
@@ -69,6 +81,15 @@ final class StudioController extends AdminController
|
||||
}
|
||||
$repo = new Repository();
|
||||
$page = $repo->page($slug);
|
||||
$area = $request->get('area');
|
||||
if ($page && $page['layout_kind'] === null && in_array($area, ['header', 'footer'], true)) {
|
||||
try {
|
||||
$page[$area . '_id'] = DesignLibrary::selection($area, $request->get('choice'));
|
||||
$page['visibility'][$area] = true;
|
||||
} catch (RuntimeException $error) {
|
||||
return $this->error($request, $this->validationMessage($error), 422);
|
||||
}
|
||||
}
|
||||
|
||||
return $page ? (new SiteController())->renderPage($repo, $page, true, $request->get('canvas') === '1') : $this->error($request, '找不到此页面。', 404);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user