API / Minn\Theme / TemplateIndex

TemplateIndex final class

Minn\Theme\TemplateIndex · public/minn/src/Minn/Theme/TemplateIndex.php · 304 lines

Every block template and template part the site offers, in the order the reference lists them: the rows the site editor saved first (newest post date first), then the theme's own files in the order the directory hands them back, then whatever a plugin registered. A saved row shadows the theme file of the same slug and reports has_theme_file so the file can be restored by deleting the row.

Constants and properties

constTEMPLATE = 'wp_template'
constPART = 'wp_template_part'
privatestatic ?array $defaults
privatereadonly Minn\Db $db

Promoted from the constructor.

privatereadonly Minn\Theme\Theme $theme

Promoted from the constructor.

privatereadonly Minn\Content\Site $site

Promoted from the constructor.

privatereadonly ?Minn\Runtime\BlockTemplates $registered

Promoted from the constructor.

Public

new__construct(Minn\Db $db, Minn\Theme\Theme $theme, Minn\Content\Site $site, ?Minn\Runtime\BlockTemplates $registered = NULL)#
methodall(string $type): array#

Every template of a type: the theme's files with the saved rows over them.

@return list<TemplateRecord>
methodfind(string $type, string $id): ?Minn\Theme\TemplateRecord#

Null when the id names another theme, or a slug nothing provides.

methodpostRecord(array $row): Minn\Theme\TemplateRecord#

A saved wp_template or wp_template_part row as a template. @param array<string, mixed> $row

$rowarray<string, mixed>
methodfiles(string $type): array#

The theme's files of a type, in the directory's order, each as _get_block_templates_files describes it (fileInfo).

@return list<array<string, mixed>>
methodfileInfo(string $type, string $slug): ?array#

One theme file: its slug, path, theme (the parent's for a file the child does not have) and type; a part's title (when theme.json gives one) and area; a custom template's title and post types. Null when the theme has no such file.

@return array<string, mixed>|null
methodpostTypes(string $slug): array#

The post types a custom template declares; none for any other template.

@return list<string>
methodthemeSlug(): string#

The theme the index reads.

methodhasFile(string $type, string $slug): bool#

Whether the theme ships a file for a slug.

methodauthorText(Minn\Theme\TemplateRecord $record): string#

Who the caller is told made this: the theme's own name for anything that has a file behind it, the plugin for a registered one, the author's display name for a row a person saved, and the site's name when nobody is recorded.

methodoriginalSource(Minn\Theme\TemplateRecord $record): string#

theme when a file backs it, plugin when one registered it, user when someone saved it, else site.

staticisCustom(string $slug): bool#

A slug the reference does not name in its default template types is a custom template.

staticdefaults(): array#

The default template types.

@return array<string, array{title: string, description: string}>
methodmarkup(string $content): string#

Markup as a caller of the REST route sees it: patterns spliced in where the template only named them, then every template-part block told which theme it belongs to. A record carries the markup as stored, because that is what get_block_templates() hands a plugin.

Internals 7

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

privatesavedRows(string $type): array#
@return list<array<string, mixed>>
privatepluginRows(string $type): array#
@return list<array<string, mixed>>
privatefromRow(array $row, string $type): Minn\Theme\TemplateRecord#
$rowarray<string, mixed>
privatefromFile(string $slug, string $type): Minn\Theme\TemplateRecord#
privatefromPlugin(array $row, string $type): Minn\Theme\TemplateRecord#
$rowarray<string, mixed>
privatefileTitle(string $slug, string $type): string#

A theme file's title: the default template types name the hierarchy slugs, theme.json names the rest, and a slug neither knows about is its own title, verbatim rather than prettified.

privatesavedArea(int $postId, string $slug): string#