@use('Core\Localization\Locales') @use('Layout\Blocks\BlockField') {{-- Campo de um bloco do catálogo no editor da home (P5.S2.1 — emenda ADR-016). - O rótulo e o vocabulário do campo vêm do **catálogo** (`layout::blocks.fields.*`): o mesmo texto serve Home e Páginas sem duplicar tradução. - `$oldValue` já vem resolvido pelo chamador (`old($errorKey, $value)`), então um erro de validação não apaga o que o operador digitou. - O erro é sempre server-side (`$errors`), mostrado junto do campo e referenciado por `aria-describedby`; o resumo `role="alert"` é do formulário (`x-cms::form-errors`). - Nada de HTML/Blade/CSS no dado: só controles nativos; texto rico é AST (ADR-028) e mídia é **id** do catálogo (ADR-026). - Campo **traduzível** (P5.S2.2) abre um grupo com um controle por locale (pt_BR/en/es/fr); o nome vira `campo[locale]` e o mapa é validado pelo schema do tipo (texto/AST). O locale default é o fallback do portal quando um idioma não for traduzido. @var BlockField $field @var string $name nome do input (ex.: `sections[0][props][title]`) @var string $errorKey chave no error bag (ex.: `sections.0.props.title`) @var string $id base dos ids do campo @var mixed $oldValue valor corrente (old() já aplicado) --}} @php $label = __('layout::blocks.fields.'.$field->name); $error = $errors->first($errorKey); $errorId = $id.'-error'; $helpId = $id.'-help'; $help = match ($field->type) { 'media' => __('home::cms.media_help'), 'ast' => __('home::cms.ast_help'), 'icon' => __('home::cms.icon_help'), default => null, }; $describedBy = implode(' ', array_filter([ $help !== null ? $helpId : null, $error !== null ? $errorId : null, ])); $ariaInvalid = $error !== null ? 'true' : null; $scalarValue = is_scalar($oldValue) ? (string) $oldValue : ''; $astValue = is_array($oldValue) ? (string) json_encode($oldValue, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) : $scalarValue; $translations = $field->translatable ? $field->translations($oldValue) : []; @endphp @if ($field->translatable)
{{ $label }}@if ($field->required)@endif @if ($error !== null) {{ $error }} @endif
@foreach (Locales::all() as $locale) @php $localeValue = old($errorKey.'.'.$locale, $translations[$locale] ?? null); $localeId = $id.'-'.$locale; $localeName = $name.'['.$locale.']'; $localeScalar = is_scalar($localeValue) ? (string) $localeValue : ''; $localeValueText = is_array($localeValue) ? (string) json_encode($localeValue, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) : $localeScalar; @endphp
@if ($field->type === 'text' || $field->type === 'ast') @else max !== null) maxlength="{{ $field->max }}" @endif @if ($describedBy !== '') aria-describedby="{{ $describedBy }}" @endif @if ($ariaInvalid !== null) aria-invalid="true" @endif class="input input-bordered w-full"> @endif
@endforeach
@if ($help !== null) {{ $help }} @endif
@elseif ($field->type === 'bool')
@if ($help !== null) {{ $help }} @endif @if ($error !== null) {{ $error }} @endif
@elseif ($field->type === 'list')
{{ $label }}@if ($field->required)@endif @php $rows = is_array($oldValue) ? array_values($oldValue) : []; $limit = $field->max; $canAdd = $limit === null || count($rows) < $limit; // Uma linha em branco por lista: sem JS dá para adicionar um item por gravação; a // linha totalmente vazia é descartada pela Action (nunca vira erro). if ($canAdd) { $rows[] = []; } @endphp @if ($error !== null) {{ $error }} @endif
@foreach ($rows as $itemIndex => $row)
{{ __('home::cms.item', ['position' => $itemIndex + 1]) }}
@foreach ($field->items ?? [] as $itemField) @php $itemName = $name.'['.$itemIndex.']['.$itemField->name.']'; $itemErrorKey = $errorKey.'.'.$itemIndex.'.'.$itemField->name; $itemId = $id.'-'.$itemIndex.'-'.$itemField->name; $itemValue = old($itemErrorKey, is_array($row) ? $row[$itemField->name] ?? null : null); @endphp @include('home::cms.partials.home-block-field', [ 'field' => $itemField, 'name' => $itemName, 'errorKey' => $itemErrorKey, 'id' => $itemId, 'oldValue' => $itemValue, ]) @endforeach
@endforeach
@if ($canAdd)

{{ __('home::cms.add_item_hint') }}

@endif
@elseif ($field->type === 'link')
{{ $label }} @php($linkValue = is_array($oldValue) ? $oldValue : [])
@include('home::cms.partials.home-block-field', [ 'field' => new BlockField(name: 'label', type: 'string', max: 60), 'name' => $name.'[label]', 'errorKey' => $errorKey.'.label', 'id' => $id.'-label', 'oldValue' => old($errorKey.'.label', $linkValue['label'] ?? null), ]) @include('home::cms.partials.home-block-field', [ 'field' => new BlockField(name: 'url', type: 'url'), 'name' => $name.'[url]', 'errorKey' => $errorKey.'.url', 'id' => $id.'-url', 'oldValue' => old($errorKey.'.url', $linkValue['url'] ?? null), ])
@if ($error !== null) {{ $error }} @endif
@else
@if ($field->type === 'text' || $field->type === 'ast') @elseif ($field->values !== null) @else type === 'int') type="number" @if ($field->min !== null) min="{{ $field->min }}" @endif @if ($field->max !== null) max="{{ $field->max }}" @endif @elseif ($field->type === 'url') type="url" @else type="text" @if ($field->max !== null) maxlength="{{ $field->max }}" @endif @endif @if ($field->required) required @endif @if ($describedBy !== '') aria-describedby="{{ $describedBy }}" @endif @if ($ariaInvalid !== null) aria-invalid="true" @endif class="input input-bordered w-full"> @endif @if ($help !== null) {{ $help }} @endif @if ($error !== null) {{ $error }} @endif
@endif