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
| const | TEMPLATE = 'wp_template' | |
| const | PART = 'wp_template_part' | |
| private | static ?array $defaults | |
| private | readonly Minn\Db $db | Promoted from the constructor. |
| private | readonly Minn\Theme\Theme $theme | Promoted from the constructor. |
| private | readonly Minn\Content\Site $site | Promoted from the constructor. |
| private | readonly ?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)# | ||||
| method | all(string $type): array# | Every template of a type: the theme's files with the saved rows over them. @return list<TemplateRecord> | |||
| method | find(string $type, string $id): ?Minn\Theme\TemplateRecord# | Null when the id names another theme, or a slug nothing provides. | |||
| method | postRecord(array $row): Minn\Theme\TemplateRecord# | A saved wp_template or wp_template_part row as a template. @param array<string, mixed> $row
| |||
| method | files(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>> | |||
| method | fileInfo(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 | |||
| method | postTypes(string $slug): array# | The post types a custom template declares; none for any other template. @return list<string> | |||
| method | themeSlug(): string# | The theme the index reads. | |||
| method | hasFile(string $type, string $slug): bool# | Whether the theme ships a file for a slug. | |||
| method | authorText(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. | |||
| method | originalSource(Minn\Theme\TemplateRecord $record): string# | theme when a file backs it, plugin when one registered it, user when someone saved it, else site. | |||
| static | isCustom(string $slug): bool# | A slug the reference does not name in its default template types is a custom template. | |||
| static | defaults(): array# | The default template types. @return array<string, array{title: string, description: string}> | |||
| method | markup(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.
| private | savedRows(string $type): array# | @return list<array<string, mixed>> | |||
| private | pluginRows(string $type): array# | @return list<array<string, mixed>> | |||
| private | fromRow(array $row, string $type): Minn\Theme\TemplateRecord# |
| |||
| private | fromFile(string $slug, string $type): Minn\Theme\TemplateRecord# | ||||
| private | fromPlugin(array $row, string $type): Minn\Theme\TemplateRecord# |
| |||
| private | fileTitle(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. | |||
| private | savedArea(int $postId, string $slug): string# |
Nothing matches.