feat: lit/tb-create-template – disabled templates, all or nothing

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-27 16:09:49 +02:00
co-authored by Claude Opus 5.5
parent 54922a9f7e
commit 42b9b384d5
10 changed files with 1165 additions and 46 deletions
@@ -6,8 +6,6 @@ namespace LIT\MCP\Integrations\Divi\Pages;
use Closure;
use LIT\MCP\Abilities\Errors;
use LIT\MCP\Integrations\Divi\BlockTree\Block;
use LIT\MCP\Integrations\Divi\BlockTree\Document;
use LIT\MCP\Integrations\Divi\BlockTree\NodeIndex;
use LIT\MCP\Integrations\Divi\BlockTree\Outline;
use LIT\MCP\Integrations\Divi\BlockTree\Serializer;
@@ -70,7 +68,7 @@ final class DiviContentComposer implements ContentComposer
);
}
$layout = $this->layout($this->composition->forPost(0), $sections);
$layout = LayoutBuilder::build($this->composition->forPost(0), $sections, 'divi');
return $layout instanceof WP_Error ? $layout : null;
}
@@ -78,7 +76,7 @@ final class DiviContentComposer implements ContentComposer
public function write(int $postId, string $postType, array $sections): array|WP_Error
{
$composition = $this->composition->forPost($postId);
$layout = $this->layout($composition, $sections);
$layout = LayoutBuilder::build($composition, $sections, 'divi');
if ($layout instanceof WP_Error) {
return $layout;
}
@@ -98,37 +96,4 @@ final class DiviContentComposer implements ContentComposer
'edit_url' => DiviPage::builderUrl($postId),
];
}
/**
* The whole description composed and inserted into an empty document – or every error.
*
* @param list<mixed> $sections
* @return array{document: Document, blocks: list<Block>}|WP_Error
*/
private function layout(DiviComposition $composition, array $sections): array|WP_Error
{
if ($sections === []) {
return Errors::invalidInput('Kein Divi-Inhalt angegeben; nichts wurde angelegt.', [
'divi' => 'mindestens ein Abschnitt',
]);
}
$composed = $composition->composer()->compose(array_values($sections), null, 'divi');
if ($composed['errors'] !== []) {
return DiviErrors::composed($composed, 'Divi-Inhalt ist ungültig; nichts wurde angelegt.');
}
$document = new Document();
$violation = $composition->editor()->insert(
['container' => $document, 'parent' => null, 'index' => PHP_INT_MAX],
$composed['blocks']
);
if ($violation !== null) {
return Errors::invalidInput('Divi-Inhalt passt nicht auf die Seite; nichts wurde angelegt.', [
'divi' => $violation,
]);
}
return ['document' => $document, 'blocks' => $composed['blocks']];
}
}