PHP API
Two facades with static methods cover programmatic document work; the REST API and the bundle CLI commands use them too.
Renick\Content\Classes\Content
The write-safe facade. Every write normalizes and strictly validates the document (ApplicationException on failure), snapshots the previous state so it can be undone, saves the host in its own site context, records a version and reindexes media usage.
| Method | Behaviour |
|---|---|
get(Model $host, string $field): array | decoded document; ['blocks' => []] when empty or invalid |
put(Model $host, string $field, string|array $document, string $action = 'import'): array | the write above; returns the normalized document |
duplicate(Model $host, string $field, ?Model $targetHost = null): array | copy with fresh block ids, written to $targetHost if given |
export(Model $host, string $field): array | ['document' => …, 'media' => [paths…]] |
import(Model $host, string $field, array $bundle, string $mode = 'replace'): array | writes $bundle['document']; only mode replace exists |
exportBundle(Model $host, string $field): string | ZIP bytes: document.json, manifest.json, media/<path>; missing files are listed in the manifest |
exportBundleToFile(Model $host, string $field): string | the same ZIP as a temp file the caller deletes |
importBundle(Model $host, string $field, string $zipBytes, string $mode = 'replace', bool $overwriteMedia = false): array | writes the document, then restores media (existing files kept unless $overwriteMedia); returns document, media (restored, skipped, failed) and portability. Failed media throw BundleImportException with the partial result in getResult() |
applyTemplate(Model $host, string $field, Template $template): array | replaces the document with a re-id'd template copy |
translate(Model $host, string $field, string $targetLanguage, ?string $sourceLanguage = null): array | AI-translates and writes; returns ['document' => …, 'warning' => ?string] |
Versions are deduplicated by content hash; the newest 50 unpinned snapshots per host and field are kept (renick.content::versions.keep).
Renick\Content\Classes\ContentApi
Pure helpers without persistence:
| Method | Behaviour |
|---|---|
duplicateDocument(string|array $document): string|array | deep copy with fresh b_… ids; returns the type it was given |
duplicateBlock(array $block): array | fresh ids for one block subtree |
toPlainText(string|array $document): string | text of text, title, caption, alt, author, label and tag-stripped html, for search and SEO |
excerpt(string|array $document, int $limit = 160): string | shortened plain text |
Call duplicateDocument() whenever you clone a record that carries a document: block ids must stay unique per document.
Events
Most events are on Events. The media and AI events:
| Event | Fired | Payload / return |
|---|---|---|
renick.content.media.collectUsage | on every media reindex of a host + field | ($host, $fieldName, $decodedDocument); return extra media paths to add to the usage index and delete guard |
renick.content.ai.beforeRequest | before every AI chat request (halting) | (&$payload) by reference; return a modified array to replace it |
php
Event::listen('renick.content.media.collectUsage', function ($host, $fieldName, $document) {
return ['/seo/og-image.png'];
});