forked from laysense/laysite
Fix design validation, canonical routes, media headers and favicon
This commit is contained in:
@@ -5,7 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Content\Assets;
|
||||
use App\Content\Buttons;
|
||||
use App\Content\DesignFieldError;
|
||||
use App\Content\DesignLibrary;
|
||||
use App\Content\Repository;
|
||||
use App\Content\SiteDesign;
|
||||
@@ -40,13 +40,17 @@ final class DesignController extends AdminController
|
||||
return $this->error($request, '找不到这项设计配置。', 404);
|
||||
}
|
||||
$error = '';
|
||||
$field = '';
|
||||
$secret = '';
|
||||
$links = SiteDesign::linkText($item['payload']['links'] ?? []);
|
||||
$default = $id !== null && ((new Repository())->site()[$kind . '_id'] ?? null) === $id;
|
||||
if ($request->method() === 'POST') {
|
||||
try {
|
||||
$savedProvider = $item['payload']['provider'] ?? [];
|
||||
$secret = '';
|
||||
$item['name'] = $this->input($request, 'name');
|
||||
$item['preset'] = $this->input($request, 'preset');
|
||||
$item['version'] = $this->version($request);
|
||||
$default = $request->post('make_default') === '1';
|
||||
if ($kind === 'palette') {
|
||||
foreach (DesignLibrary::COLORS as $color => $definition) {
|
||||
$item['payload'][$color] = $this->input($request, $color);
|
||||
@@ -54,11 +58,11 @@ final class DesignController extends AdminController
|
||||
} else {
|
||||
$url = $this->input($request, 'action_url');
|
||||
$label = $this->input($request, 'action_label');
|
||||
$links = $this->input($request, 'links', trimValue: false);
|
||||
$item['payload'] = [
|
||||
'components' => $request->post('components', []),
|
||||
'brand' => $this->input($request, 'brand'), 'logo' => $this->input($request, 'logo'),
|
||||
'text' => $this->input($request, 'text'), 'legal' => $this->input($request, 'legal'),
|
||||
'links' => SiteDesign::parseLinks($this->input($request, 'links')),
|
||||
'action' => $url === '' && $label === '' ? [] : [[$url, $label, $this->input($request, 'action_style'), $request->post('action_blank') === '1']],
|
||||
'provider' => $savedProvider,
|
||||
];
|
||||
@@ -69,20 +73,32 @@ final class DesignController extends AdminController
|
||||
}
|
||||
$secret = $this->input($request, 'provider_secret', trimValue: false);
|
||||
}
|
||||
try {
|
||||
$item['payload']['links'] = SiteDesign::parseLinks($links);
|
||||
} catch (RuntimeException $ex) {
|
||||
throw new DesignFieldError('links', $ex->getMessage());
|
||||
}
|
||||
}
|
||||
$default = $request->post('make_default') === '1';
|
||||
$id = DesignLibrary::save($kind, $id, $item['name'], $item['preset'], $item['payload'], $this->version($request), $default, $secret);
|
||||
$id = DesignLibrary::save($kind, $id, $item['name'], $item['preset'], $item['payload'], $item['version'], $default, $secret);
|
||||
|
||||
return $this->success($request, "/admin/design/$kind/$id?saved=1");
|
||||
} catch (RuntimeException $ex) {
|
||||
$error = $this->validationMessage($ex);
|
||||
$item['payload'] = DesignLibrary::defaults($kind);
|
||||
$field = $ex instanceof DesignFieldError ? $ex->field : '';
|
||||
}
|
||||
}
|
||||
|
||||
if ($kind !== 'palette') {
|
||||
$components = $item['payload']['components'];
|
||||
$item['payload']['components'] = is_array($components) ? array_values(array_intersect(
|
||||
array_filter($components, 'is_string'), array_keys(DesignLibrary::COMPONENTS[$kind])
|
||||
)) : [];
|
||||
}
|
||||
|
||||
return $this->render($request, 'admin-design-edit', [
|
||||
'title' => '设计配置', 'kind' => $kind, 'key' => $key, 'item' => $item, 'default' => $default,
|
||||
'error' => $error, 'saved' => $request->get('saved') === '1',
|
||||
'error' => $error, 'field' => $field, 'links' => $links, 'reenterSecret' => $error !== '' && $secret !== '',
|
||||
'saved' => $error === '' && $request->get('saved') === '1',
|
||||
], $error === '' ? 200 : 422);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user