$attrs * @param array> $content * @param array $fields * @param array $headerButtons * @param array $buttons */ public function render( array $attrs, array $bodyAttrs, array $content, array $fields, array $headerButtons, array $buttons, array $schema, array $scripts, FormNodeRenderContext $context ): string { $isPage = strval($schema['mode'] ?? '') === 'page'; if ($isPage) { return $this->renderPageShell($attrs, $bodyAttrs, $content, $fields, $headerButtons, $buttons, $schema, $scripts, $context); } $html = sprintf('
', $context->attrs($attrs)); $html .= "\n\t" . sprintf('
', $context->attrs($bodyAttrs)); if (count($content) > 0) { $html .= $context->renderChildren($content); } else { $html .= join("\n", $fields); if (count($buttons) > 0) { $html .= "\n\t\t"; $html .= (new FormActionBarRenderer())->render([ 'type' => 'actions', 'attrs' => ['class' => 'layui-form-item text-center'], 'children' => array_map(static fn(string $button): array => ['type' => 'button', 'html' => $button], $buttons), ], $context); } } if ($schemaScript = (new JsonScriptRenderer())->render($schema, 'form-builder-schema')) { $html .= "\n\t\t" . $schemaScript; } $html .= "\n\t" . '
'; return $html . "\n
" . (new InlineScriptRenderer())->render($scripts); } private function renderPageShell( array $attrs, array $bodyAttrs, array $content, array $fields, array $headerButtons, array $buttons, array $schema, array $scripts, FormNodeRenderContext $context ): string { $header = (new PageHeaderRenderer())->render(strval($schema['title'] ?? ''), $headerButtons); $form = sprintf('
', $context->attrs($attrs)); $form .= "\n\t\t\t\t" . sprintf('
', $context->attrs($bodyAttrs)); if (count($content) > 0) { $form .= "\n\t\t\t\t\t" . $context->renderChildren($content); } else { $form .= "\n\t\t\t\t\t" . join("\n", $fields); if (count($buttons) > 0) { $form .= "\n\t\t\t\t\t"; $form .= (new FormActionBarRenderer())->render([ 'type' => 'actions', 'attrs' => ['class' => 'layui-form-item text-center'], 'children' => array_map(static fn(string $button): array => ['type' => 'button', 'html' => $button], $buttons), ], $context); } } if ($schemaScript = (new JsonScriptRenderer())->render($schema, 'form-builder-schema')) { $form .= "\n\t\t\t\t\t" . $schemaScript; } $form .= "\n\t\t\t\t" . '
'; $form .= "\n\t\t\t" . '
'; $form .= (new InlineScriptRenderer())->render($scripts); $html = sprintf( '
', htmlentities(strval($schema['preset'] ?? 'page-form'), ENT_QUOTES, 'UTF-8') ); if ($header !== '') { $html .= "\n\t" . $header; $html .= "\n\t" . '
'; } $html .= "\n\t" . '
'; $html .= "\n\t\t" . '
'; $html .= "\n\t\t\t" . '
'; $html .= "\n\t\t\t\t" . $form; $html .= "\n\t\t\t" . '
'; $html .= "\n\t\t" . '
'; $html .= "\n\t" . '
'; return $html . "\n
"; } }