API / Minn\Theme / TemplateWriter

TemplateWriter final readonly class

Minn\Theme\TemplateWriter · public/minn/src/Minn/Theme/TemplateWriter.php · 116 lines

Saving and removing block templates. A template the theme ships is never touched on disk: editing one writes a wp_template row that shadows the file, and deleting that row is what "reset to the theme version" means.

Constants and properties

privatereadonly Minn\Db $db

Promoted from the constructor.

privatereadonly Minn\Content\PostWriter $writer

Promoted from the constructor.

privatereadonly Minn\Content\Terms $terms

Promoted from the constructor.

privatereadonly Minn\Content\Site $site

Promoted from the constructor.

privatereadonly Minn\Theme\TemplateIndex $index

Promoted from the constructor.

Public

new__construct(Minn\Db $db, Minn\Content\PostWriter $writer, Minn\Content\Terms $terms, Minn\Content\Site $site, Minn\Theme\TemplateIndex $index)#
methodsave(Minn\Theme\TemplateRecord $record, array $fields, int $authorId): int#

Writes the site's own copy of a template, creating the row the first time. Returns the post id.

$fieldsarray{title?: string, content?: string, description?: string, area?: string}
methodcreate(Minn\Theme\TemplateRecord $record, array $fields, int $authorId): int#

A new site copy from the collection's create: as a save inserts one, but recording no origin, even over a theme file (probe rest-template-create).

$fieldsarray<string, string>
methodtrash(Minn\Theme\TemplateRecord $record): void#

Moves a site copy to the trash, which hands the theme's file back.

methoddestroy(Minn\Theme\TemplateRecord $record): void#

Deletes a saved template row.

Internals 3

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privateinsert(Minn\Theme\TemplateRecord $record, array $fields, int $authorId): int#

The site copy's row, its theme term and its area.

$fieldsarray<string, string>
privatesetArea(int $postId, ?string $area, string $type): void#
privatethemeTermId(): int#