fix(core): 레이아웃 코드 편집 화면 설명의 미해석 표기 노출 해소

파일 목록과 선택한 파일의 설명에 `$t:…` / `{{ … }}` 가 그대로 보였다.
설명 원문은 소유 템플릿의 다국어 키인데 응답 조립 시점에는 요청 템플릿의
사전만 열려 있어 다른 템플릿의 레이아웃을 편집하면 키를 찾지 못했다.
번역 실패가 예외 없이 원문 노출로 이어져 화면에만 나타났다.

목록·상세가 같은 규칙을 쓰도록 표시 해석을 App\Support\LayoutDescription 으로
모으고, 컨트롤러가 소유 템플릿 사전을 주입한다. 표현식이 섞인 설명과 번역을
찾지 못한 경우는 파일 이름으로 대체한다.

목록만 고치면 상세 헤더에 그대로 남는다 — 브라우저 실측에서 목록 수정 후에도
헤더가 새던 것을 확인해 상세 경로(LayoutResource)까지 함께 처리했다.
This commit is contained in:
HeuJung committed 2026-08-04 10:21:00 +09:00
1 parent 65378fdeb6
commit e426498fb3
7 files changed
+244 -6

No files matched your search

@@ -49,9 +49,16 @@ class LayoutController extends AdminBaseController
// 동기화 / 위지윅에서 넘어온 ?route= 로 해당 파일 복원에 사용한다.
$routePathMap = $this->templateService->getLayoutRoutePathMap($templateName);
// 레이아웃 설명(`meta.description`)은 그 레이아웃을 소유한 템플릿의 사전 키를 쓴다.
// 코드 편집 화면은 관리자 템플릿 사전으로 렌더하므로 유저 템플릿 키를 알지 못해,
// 해석하지 않고 내보내면 설명 칸에 `$t:user.…` 가 원문으로 노출된다.
$translations = $this->resolveTemplateTranslations($templateName);
$collection = LayoutListResource::collection($layouts);
$collection->collection->transform(
fn (LayoutListResource $resource) => $resource->withRoutePathMap($routePathMap)
fn (LayoutListResource $resource) => $resource
->withRoutePathMap($routePathMap)
->withTranslations($translations)
);
return $this->success('common.success', $collection);
@@ -80,7 +87,8 @@ class LayoutController extends AdminBaseController
return $this->success(
'common.success',
new LayoutResource($layout)
(new LayoutResource($layout))
->withTranslations($this->resolveTemplateTranslations($templateName))
);
}
@@ -109,7 +117,8 @@ class LayoutController extends AdminBaseController
return $this->success(
'common.success',
new LayoutResource($layout)
(new LayoutResource($layout))
->withTranslations($this->resolveTemplateTranslations($templateName))
);
} catch (ConcurrentModificationException $e) {
DB::rollBack();
@@ -264,4 +273,25 @@ class LayoutController extends AdminBaseController
);
}
}
/**
* 목록 설명 해석에 쓸 소유 템플릿 사전을 로드합니다.
*
* 활성 로케일 기준이며, 로드에 실패하면 빈 배열을 돌려준다 — 그 경우
* {@see LayoutListResource} 가 레이아웃 이름으로 폴백하므로 목록은 계속 그려진다.
*
* @param string $templateName 템플릿 식별자
* @return array<string, mixed> 템플릿 프론트엔드 다국어 데이터
*/
private function resolveTemplateTranslations(string $templateName): array
{
$result = $this->templateService->getLanguageDataWithModules(
$templateName,
app()->getLocale()
);
return ($result['success'] ?? false) && is_array($result['data'] ?? null)
? $result['data']
: [];
}
}
+18 -1
View File
@@ -2,6 +2,7 @@
namespace App\Http\Resources;
use App\Support\LayoutDescription;
use Carbon\Carbon;
use Illuminate\Http\Request;
@@ -27,6 +28,9 @@ class LayoutListResource extends BaseApiResource
/** @var array<string, string|null> 레이아웃 이름 → 라우트 path 매핑 */
private array $routePathMap = [];
/** @var array<string, mixed> 소유 템플릿의 프론트엔드 다국어 사전 (점 표기 중첩) */
private array $translations = [];
/**
* 라우트 path 매핑을 주입합니다.
*
@@ -40,6 +44,19 @@ class LayoutListResource extends BaseApiResource
return $this;
}
/**
* 설명 해석에 쓸 소유 템플릿 사전을 주입합니다.
*
* @param array $translations 템플릿 프론트엔드 다국어 데이터
* @return $this
*/
public function withTranslations(array $translations): self
{
$this->translations = $translations;
return $this;
}
/**
* 목록 행을 배열로 변환합니다.
*
@@ -55,7 +72,7 @@ class LayoutListResource extends BaseApiResource
'id' => $this->getValue('id'),
'template_id' => $this->getValue('template_id'),
'name' => $name,
'description' => $this->getValue('description') ?: $name,
'description' => LayoutDescription::resolve($this->getValue('description'), $name, $this->translations),
// 이 레이아웃을 사용하는 라우트의 path (routes.json 기준). 파일 선택 시 ?route=
// 동기화 / 위지윅에서 넘어온 ?route= 로 해당 파일 복원에 사용.
+20 -1
View File
@@ -2,6 +2,7 @@
namespace App\Http\Resources;
use App\Support\LayoutDescription;
use Illuminate\Http\Request;
class LayoutResource extends BaseApiResource
@@ -16,6 +17,22 @@ class LayoutResource extends BaseApiResource
*/
protected array $routePathMap = [];
/** @var array<string, mixed> 소유 템플릿의 프론트엔드 다국어 사전 */
protected array $translations = [];
/**
* 설명 해석에 쓸 소유 템플릿 사전을 주입합니다.
*
* @param array<string, mixed> $translations 템플릿 프론트엔드 다국어 데이터
* @return $this
*/
public function withTranslations(array $translations): static
{
$this->translations = $translations;
return $this;
}
/**
* 레이아웃 이름 → 라우트 path 매핑을 주입합니다.
*
@@ -45,7 +62,9 @@ class LayoutResource extends BaseApiResource
'id' => $this->getValue('id'),
'template_id' => $this->getValue('template_id'),
'name' => $name,
'description' => $content['meta']['description'] ?? $name,
// 설명은 소유 템플릿 사전 키를 쓰므로 서버가 해석한다 — 목록(LayoutListResource)과
// 같은 규칙이어야 파일 목록과 선택 파일 헤더의 표기가 어긋나지 않는다.
'description' => LayoutDescription::resolve($content['meta']['description'] ?? null, $name, $this->translations),
'endpoint' => $content['endpoint'] ?? null,
// 이 레이아웃을 사용하는 라우트의 path (routes.json 기준). 코드 편집기가
// 파일 선택 시 ?route= 동기화 / 위지윅에서 넘어온 ?route= 복원에 사용.