MMOframework
Pourquoi l'IA Playground Bibliothèques Développeurs Agence
FR EN
Créer un projet en direct
Index
# Content editing — a developer's guide How to change what the editors of a site built on mmo.editor edit, and how the public site prints it: a section type, a field, records of their own (articles, events, offers...), the blocks a type of record offers, the lists an editor picks from, the images and files (mmo.edms). Each recipe lists every file it touches, in order, and how to check it. The reference of each piece is elsewhere: [Pages.md](Pages.md) (the pages, the sections, their api and backoffice), [Overview.md](Overview.md) (``), mmo.edms' `docs/mcp/Overview.md` (the files), mmo.client's docs (`.jhs`, ``, the views), mmo.core's (entities, repositories, the data api). A project using mmo.editor may add its own part to this guide: `docs/content-editing.md` at its root, shown after this one in its Developer › Content editing page (dev mode, the developer layer on). --- ## 1. The pieces ``` editor (admin) server visitor (public site) ───────────── ────── ──────────────────── ── admin/pages.json ─▶ Pages, Page (draft, published, revisions) ──▶ PublicPageController form from the section schemas SectionType = {name}.schema.json PageRenderer (PUBLIC) live preview (PageRenderer PREVIEW) + {name}.phtml + sections.css └─ a template per section, $f = SectionFields + a view (.jhs) ─ data/{repo}/{collection}.json ─▶ entities of a repository ──▶ a section's `query` field (records of their own) (a RepositoryController of (JsonRepository...) (CollectionQuery), and an the project's own) address per record (`entities`) , , ─ edms/... ─▶ mmo.edms files, labels ───────────▶ edms/public/{id}/{name}?w=… ``` - **A page** is a list of sections, each `{id, type, data}`: its data is checked against its type's schema (`SectionType::clean`, every object closed: an undeclared field is refused), drafted, published, kept in revisions. - **A section type** is three files of a `sections/` folder of `Pages`' `templates`: `{name}.schema.json` (its fields: what the page editor's form shows), `{name}.phtml` (how it prints, `$f = $_VARS['f']`), styles in `sections.css`. Beside it: its **variants** (`sections/{type}/{name}.phtml`, the ways it prints) and the **blocks** of records (`sections/_blocks/{name}.*`) -- all three made and overridden in the section-type editor. A type saved by the section-type editor on a server overrides the shipped one (`typesFolder`, `TypeOverrides`). - **A record of its own** (an article): an entity of a repository, edited in an admin page (`` and its view), shown by the sections that query it (`"format": "query"`) and, if wanted, at an address of its own (`PublicPageController`'s `entities`). - **An image or a file**: a file of mmo.edms in a public label, kept by its address relative to the site (`edms/public/{id}/{name}`): the same on every server the data is copied to. ## 2. Where should the content live? | the content | where | why | |---|---|---| | a text, an image, a button of one page | a field of a section | edited where it is seen, drafted and published with the page | | a list that belongs to one page (the 4 expertises) | an `array` field of a section (`$f->each()`) | same | | things that grow without end, are shown on several pages, filtered, sorted, each at its own address (news, projects, offers) | records of their own (§5) + a `query` field (§6) | a table to manage them, no page to republish for each | | a choice an editor must not misspell (a category) | records of their own, picked from (§8) | renamed once, everywhere | | optional parts of a record that depend on its kind (an event's dates, an offer's contact) | blocks chosen by a type record (§7) | the form shows only what applies | | a photo, a pdf | mmo.edms (§9) | one library, public addresses, narrower copies, no file in the release | ## 3. Recipe — a new section type 1. **`{templates}/sections/{name}.schema.json`** — `label`, `icon`, `description` (the « Add a section » list), `properties`. Each field: `type`, `label`, `help`, `default` (in English, translated when shown), `level` (`standard`, `expert`: hidden in simple mode), `format`: - `text` (default), `html` (``; `"editor": "inline"` for a title, `tools` its toolbar), `url`, `date`, `email`, `image` (`{src, alt}`), `query` (§6); with mmo.edms, `file` (a string: ``) and `gallery` (an array `[{src, alt, file}]`: ``, `maxItems`, `minWidth` the width a photo needs where it goes); an `enum` is a select (`enumLabels` its labels), `options` one read from a collection (§8); an `array` of objects a list of items. - Every object is closed: a field the template needs must be declared, or saving refuses it. 2. **`{templates}/sections/{name}.phtml`** — one root element with `$f->root('classes')`; every printed field with its helper and, for in-place editing, `$f->edit('path')` on its element: ```php root('my-quote') ?>> edit('text') ?>>html('text') ?> has('author')) { ?>edit('author') ?>>text('author') ?> image('photo', ['sizes' => '(max-width: 700px) 100vw, 320px']) ?> ``` `text()` escapes, `html()` re-sanitizes, `url()` gives `#` for an unsafe address, `image()` adds `srcset` for an mmo.edms public image (say its `sizes`), `each()` loops a list. Never `echo $f->get(...)` unescaped. 3. **`{templates}/sections/sections.css`** — the type's styles, prefixed by its own class: every section's styles are on every page, a generic name (`.facts`) will meet another type's. 4. **French** — the labels and defaults are English keys: the project's `i18n` (or the library's `src/i18n/fr.php`). 5. **Check** — the project's test that loads every type (`Pages::Shared()->getSectionTypes()->get('name')`), then the page editor: add the section, fill it at each level, preview on phone/tablet/desktop, publish, open the page. ## 4. Recipe — a new field in an existing section type 1. Add it to the schema (with its `default`, so new sections start with something sensible). 2. Print it in the template, guarded by `$f->has()` (the sections saved before have no value). 3. Sections saved before keep their data; a field **removed** from the schema is dropped from a section at its next save (closed objects): move its content first if it matters (a script over the pages' drafts and revisions). 4. A type overridden on a server (`db/cms/sections/...`, the section-type editor) does not get the change: the hub's « Section types » and the project's types page list the overrides — bring them back to `src` first. ## 5. Recipe — records of their own (an `Article`) 1. **The entity** (`src/entities/Article.php`), required by `src/bootstrap.php`: - each field an `#[ArrayProperty()]` with its docblock: `@title` (the form's and the table's label), `@maxLength`, `@pattern`, `@format date|html`; the class: `@view Article` (its form), `@unique slug`; - an **associative** array property (`{src, alt}`, `{start, end, place}`) needs `@type object`, or mmo.core loads it as an empty list; a list of objects (`[{value, label}]`) is a plain `array`; - `title` is the base entity's, `?string`. 2. **The repository** (`configs/config.json`): a repository of its own for content (`"content": JsonRepository`, `{db}/articles.json`) — not `main`, which holds the accounts and their tokens. 3. **Its data api**: a controller of the project's own extending `RepositoryController`, configured with that repository only, routed; mmo.core's `RepositoryController` itself stays unrouted and names the repositories (`main`, `content`) for mmo.oauth's scopes. The Theme's `repositoryController` names the project's controller, so `` finds `data/{repo}/{collection}.json`. Rights: `data.content.articles` (read, write) on the roles that manage them — set by the project's install command, never by hand on a server. 4. **The admin page** (`src/pages/articles/index.json` + `articles.phtml`): a ``; its rows open the entity's view. 5. **The form** (`src/views/Article.jhs`, a ``): inputs bound to the fields (`value="{title}"`, `value="{image/alt}"` for a path), mmo.client elements for the rest (``, `` for a list of objects edited in a view of its own, mmo.edms' ``, ``, ``). A table saves a row where it read it (`Entity::claim`): nothing to do for a JsonRepository whose uid names a file. 6. **An address per record** (optional): `PublicPageController`'s `entities` (`{"actualites": {"repository", "collection", "field": "slug", "where": {...}, "layout", "section", "title", "description", "image"}}`) renders a record as a page of one section whose data is the record (its own section type, `level: expert` so nobody adds it). 7. **Seed** what a new site starts with in the install command, only when the collection is empty. ## 6. Recipe — a section showing records (`"format": "query"`) The field says which collection, what an editor may choose, and what every query keeps: ```json "source": {"type": "object", "format": "query", "label": "Articles", "repository": "content", "collection": "articles", "where": {"published": true, "date": {"$lte": "{today}"}}, "filters": {"category": {"label": "Category", "type": "string", "options": {"repository": "content", "collection": "categories", "value": "name", "label": "name"}}, "featured": {"label": "Featured", "type": "boolean"}}, "sorts": {"date": "Date", "title": "Title"}, "maxLimit": 48, "default": {"sort": "-date", "limit": 6}, "item": {"properties": {"title": {"type": "string"}, "body": {"type": "string", "format": "html"}, "image": {"type": "object", "format": "image"}}}} ``` - `where` always applies, whatever an editor or a visitor chose (`{today}`, `{now}` replaced): put there what must never be seen (drafts, the future). A chosen filter never overrides it. - `options` makes a filter a list read from a collection (the page editor shows the labels; only those values are kept). - In the template: `$result = $f->query('source')` gives `items` (SectionFields, printed with their helpers and the `item` schema), `total`, `more`; `$f->skip` is what is shown already. - « Load more » and tabs: the section alone is `{page}?section={id}&skip={n}&filters[category]=…` (`PublicPageController`); a visitor's filters are kept only when the field declares them, within their choices. - Print a record's link (`actualites/{slug}`), its image with `sizes`, its text escaped. ## 7. Recipe — optional blocks chosen by a type (« a new kind of block ») When records come in kinds that need different parts (an event has dates and a place, a job offer a contact), a **type record** says which blocks its records have, in order; the form shows those, the site prints those. A block is a template of mmo.editor's (§1, [Pages.md](Pages.md) « Blocks and variants »), so a developer adds, changes, overrides or deletes one from the admin, with no release: 1. **Types de sections › « New block »** — its name (`video`: what the records keep, `blocks.video`), its fields (the « Fields » tab: the same kinds as a section's), its **zone** (`main`, with the text; `facts`, the key information a layout may put aside), its label and description. 2. **Template** — « Generate from the fields », then shape it: `$_VARS['f']` prints the block's fields (`text`, `html`, `url`, `image`, `each`: escaped), `$_VARS['record']` the record's. The preview shows it with its examples. 3. **Styles** — its own css, prefixed by its class (`.cms-video`). 4. **Save** — the types of records offer it at once (their form lists the blocks); tick it on a type: the records of that type show its fieldset (``), their page prints it where the layout puts its zone. A record's type holds its blocks by name, in order; a record holds their data in `blocks: {name: {...}}`. Deleting a block keeps the records' data (printed again once a block of that name exists); a block saved on the server replaces the shipped one of the same name until it is deleted (the overrides banner, the hub). If a block holds a file of a new kind (a video), add its type to mmo.edms' `allowedTypes` and check `maxSize` -- configuration, so a release. The same goes for the ways a section is printed: **« New variant »** of a type (`sections/{type}/{name}.phtml`): its label, help and order, a template printing what the type's template hands it. The section's « Style » offers it. Code is still needed for what is not a template: a new kind of record, a new list to pick from (§8), a new field of every record (§5), a template's shared helper. ## 8. Recipe — a list an editor picks from (categories, types) - The list is records of their own (§5): `{name, description}`, `@unique name`. - The record holds the **name** chosen (what a table and a template print as they are), picked from a `` — `option-value` makes an option hold that field rather than the entity. - Renaming one renames it in the records, and deleting one still used is refused: the project's data controller overrides `routeUpdate`/`routeDelete` (re-declaring their `#[APIRoute]`, an override without it is not routed), for the collections of a `REFERENCES` map (`collection => field of the record`); `` shows the refusal. - Seed the list from the values the records already have (the install command, when it is empty). - A section's or a block's field picks a record the same way: `"options": {"repository", "collection", "value", "label", "where", "empty"}` on a string field makes it a list of that collection (`CollectionQuery::Resolve`: the page editor and `` get its `enum` and `enumLabels`), `empty` the label of a first choice, `''`. An article's block naming a project: `{"type": "string", "options": {"repository": "content", "collection": "projects", "value": "slug", "label": "title", "empty": "None"}}` -- its template finds the project by that slug. A reference held in a path (`blocks.project.project`) renames and guards the same way, the controller walking the path. ## 9. Images and files (mmo.edms) Configuration (`configs/config.json`), once per project: ```json "MMO\\edms\\FileManager": {"repositories": {"main": {"$": "#repository"}}, "publicLabels": ["_TAGS/site"], "imageWidths": [320, 640, 1280, 1920], "allowedTypes": {"*": ["image/jpeg", "image/png", "image/webp", "image/gif", "application/pdf"]}, "maxSize": 20971520} ``` plus the `files` path (outside `www/`), `FileController` routed, the `files`/`labels` collections in the repository, and `files` in `deploy.json`'s `shared`. The install command makes the labels (`_TAGS/site`, `_TAGS/site/articles`, `_TAGS/site/pages`) and grants `edms.labels.{id of _TAGS/site}` to the roles that write the site — nothing else of edms. | where | what | |---|---| | a record's form | `` and an input for `{image/alt}`; `` (`[{src, alt, file}]`); `` | | a rich text | `` | | the page editor | ``: an image field sends there and offers « From the library » | | a template | `$f->image('image', ['sizes' => …])`: `srcset` of the `imageWidths` narrower than the image, then the image at its own width (`SectionFields::Srcset`; `sizes` is `100vw` unless given); a gallery's items `$f->image("gallery.$i")` | A file is public only in a public label, and never once in the trash, in quarantine or encrypted: a page showing it then shows nothing (the trash keeps it 30 days). Its address is kept as it is (`edms/public/12/name.jpg`): never write an absolute url (`http://localhost/...`) into content. Moving older images in: copy each into edms with `FileManager::uploadFile()` and rewrite the addresses in the stores (a command with `--dry-run`). ## 10. Security checklist - Every value printed through `SectionFields` (`text`, `html`, `url`, `image`), never raw. - A query's `where` holds what must never be public; a filter is declared, with its choices. - The data api of a project serves its content repository only; each role gets `data.{repo}.{collection}` for what it manages, set by the install command. - Public files only in public labels; a label classified for encryption never public. - A form's file/image elements send with the session's CSRF token (mmo.edms does it); nothing writes a server path into content. ## 11. Traps met for real - **`.jhs`: `render()` is the template's** — a method named `render` in an element's class replaces it: nothing is drawn. - **`.jhs`: an observed attribute is set as a property** — a getter alone throws (« has only a getter »): give it a setter. - **A view's list is array-like, not an `Array`** — a value set by the view: `JSON.parse(JSON.stringify(value))`. Echo what it gives back without redrawing, or an input being typed in loses its focus. - **`@type object`** for an associative array property, or it loads empty. - **A JsonRepository's uid names its file** (`file://…/articles.json#1`): anything deriving the collection from it is wrong — `` claims its rows (`Entity::claim`). - **A relative `fetch()` from a nested admin page** (`articles/categories`) resolves under it: build from the site's root. - **On the command line no controller is routed**: `Controller::Url()` throws — `FileController::PublicPath()` knows. - **CSS names**: every section's styles are on every page; prefix with the type's or record's own name. - **An overridden data route** must re-declare its `#[APIRoute]`. ## 12. Verify, then ship 1. The project's `phpunit`; for a library, `php tools/mmo.php verify --lib=` from the hub (and mmo.client's `npm test` for its JS). 2. The browser, logged in as the role that edits (`php admin.php agent-login --user=…`): the form, the preview, the public page, a phone width. 3. A ticket (the `mmo-change-tracking` skill), its checks in the board's checklist. 4. Release; on the server, the install command once (labels, roles); the data sync carries the content (`db/`, `files/`).