Skip to content

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.

MethodBehaviour
get(Model $host, string $field): arraydecoded document; ['blocks' => []] when empty or invalid
put(Model $host, string $field, string|array $document, string $action = 'import'): arraythe write above; returns the normalized document
duplicate(Model $host, string $field, ?Model $targetHost = null): arraycopy 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'): arraywrites $bundle['document']; only mode replace exists
exportBundle(Model $host, string $field): stringZIP bytes: document.json, manifest.json, media/<path>; missing files are listed in the manifest
exportBundleToFile(Model $host, string $field): stringthe same ZIP as a temp file the caller deletes
importBundle(Model $host, string $field, string $zipBytes, string $mode = 'replace', bool $overwriteMedia = false): arraywrites 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): arrayreplaces the document with a re-id'd template copy
translate(Model $host, string $field, string $targetLanguage, ?string $sourceLanguage = null): arrayAI-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:

MethodBehaviour
duplicateDocument(string|array $document): string|arraydeep copy with fresh b_… ids; returns the type it was given
duplicateBlock(array $block): arrayfresh ids for one block subtree
toPlainText(string|array $document): stringtext of text, title, caption, alt, author, label and tag-stripped html, for search and SEO
excerpt(string|array $document, int $limit = 160): stringshortened 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:

EventFiredPayload / return
renick.content.media.collectUsageon 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.beforeRequestbefore 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'];
});