Generate and download a PDF document
Generate a PDF from a saved record with an explicit layout button and a synchronous webhook.
Complete example: acme_record_pdf
Purpose (translated from upstream README)
Adapt (translated from upstream README)
Files relative to the system root:
├── README.md├── fixtures/│ ├── native.module.bake.json│ └── rendered.pdf├── menu.bake.json├── modules/│ └── acme_records/│ ├── acme_records.detail.json│ ├── acme_records.index.json│ └── acme_records.module.bake.json├── preview/│ └── sample.bake.json├── tests/│ └── acme_record_download.test.workflow.json├── translations/│ ├── de.json│ ├── en.json│ └── translations.bake.json├── views/│ ├── record.twig│ └── record.view.bake.json└── workflows/ └── acme_record_pdf.workflow.bake.jsonREADME.md
# acme_record_pdf
Dokumente / Records. Ein gespeicherter Datensatz wird per Layout-Knopf und synchronem Workflow als PDF angeboten. Eine einzige Twig-View liefert header/content/footer über view. Der Business-Test prüft download_offered; der PHPUnit-Test prüft die gerenderten Blöcke mit gefälschtem PDF-Transport.
## Dateien
- `modules/`: Schema sowie Detail- und Index-Layouts.- `menu.bake.json`: Navigation (in ein vorhandenes Menü übernehmen).- `translations/`: deutsche/englische Labels und Bakery-Ressource.- `workflows/`, `tests/`: ausführbare Graphen und isolierte Business-Tests mit Fixtures.- `preview/`: optionale Bakery-Beispieldaten; nur in einer Vorschau anwenden.
## Anpassen
Alle `acme_*`-Modul-, Workflow-, Event- und Ressourcen-Identifier gemeinsam umbenennen; Referenzen, Layoutpfade, Filter, Übersetzungsschlüssel und Tests mitändern. Weitere Felder in Schema, Layout und beiden Sprachen ergänzen. Dateien relativ zur Systemwurzel kopieren. Native Module aus `fixtures/` nur ergänzen, wenn sie fehlen; bestehende Definitionen zusammenführen. Menüeinträge und Vorschaudaten sind optional. Varianten separat prüfen, nicht zusätzlich zur Hauptdefinition anwenden.
Prüfen: `php bakery plan <system>`, `php bakery apply <system>`, dann `php bakery system test-run <system>`. In diesem Repository führt `AcmeFeatureExamplesTest` dieselben Plan-/Apply-Schritte und die Workflow-Tests in der wegwerfbaren PHPUnit-Systemdatenbank aus. UI-Darstellung und reine Client-Aktionen sind damit nicht geprüft.
`views/record.twig` enthält alle drei Blöcke; `views/record.view.bake.json` registriert sie. `action/export` ignoriert die Optionen `content`, `header` und `footer`: ausschließlich `view` benutzen. Name, Dateiname und Vorlage gemeinsam ändern. Der Knopf setzt einen gespeicherten Datensatz voraus. `action/downloadFile` ist gewählt, da `download_offered` den Content-Disposition-Header prüft.
Die produktive PDF-Konvertierung benötigt die konfigurierte Brezel-Export-Infrastruktur (`brezel.export.url`). CI ruft keinen Dienst auf: `AcmeFeatureExamplesTest` fälscht nur den HTTP-Transport, prüft die gerenderten header/content/footer-Blöcke und liefert `fixtures/rendered.pdf` zurück. Der normale Business-Test-Runner liefert für Laravel-HTTP derzeit eine leere generische Antwort; seine `http_fakes` erreichen diesen Exporttransport nicht. Der Workflow-/Download-Test allein belegt deshalb keine PDF-Gültigkeit und kein wkhtmltopdf-Rendering. Diese bestehende Testlücke ist im Bericht dokumentiert.fixtures/native.module.bake.json
[ { "resource_module": "views", "import": true, "resource": { "identifier": "views", "type": "views", "title": "name", "fields": [ { "identifier": "name", "type": "text" }, { "identifier": "type", "type": "text" }, { "identifier": "code", "type": "code" } ] } }, { "resource_module": "files", "import": true, "resource": { "identifier": "files", "type": "files", "title": "name", "fields": [ { "identifier": "name", "type": "text" }, { "identifier": "path", "type": "text" }, { "identifier": "mime_type", "type": "text" }, { "identifier": "size", "type": "number" } ] } }]fixtures/rendered.pdf
Binary file, base64 encoded (584 bytes):JVBERi0xLjQKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4KZW5kb2JqCjIgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzIC9LaWRzIFszIDAgUl0gL0NvdW50IDEgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2UgL1BhcmVudCAyIDAgUiAvTWVkaWFCb3ggWzAgMCAyMDAgMjAwXSAvUmVzb3VyY2VzIDw8IC9Gb250IDw8IC9GMSA0IDAgUiA+PiA+PiAvQ29udGVudHMgNSAwIFIgPj4KZW5kb2JqCjQgMCBvYmoKPDwgL1R5cGUgL0ZvbnQgL1N1YnR5cGUgL1R5cGUxIC9CYXNlRm9udCAvSGVsdmV0aWNhID4+CmVuZG9iago1IDAgb2JqCjw8IC9MZW5ndGggNDEgPj4Kc3RyZWFtCkJUIC9GMSAxMiBUZiAyMCAxNTAgVGQgKEFDTUUgSW5jLikgVGogRVQKZW5kc3RyZWFtCmVuZG9iagp4cmVmCjAgNgowMDAwMDAwMDAwIDY1NTM1IGYgCjAwMDAwMDAwMDkgMDAwMDAgbiAKMDAwMDAwMDA1OCAwMDAwMCBuIAowMDAwMDAwMTE1IDAwMDAwIG4gCjAwMDAwMDAyNDEgMDAwMDAgbiAKMDAwMDAwMDMxMSAwMDAwMCBuIAp0cmFpbGVyCjw8IC9TaXplIDYgL1Jvb3QgMSAwIFIgPj4Kc3RhcnR4cmVmCjQwMQolJUVPRgo=menu.bake.json
[ { "resource_menu": "acme_record_pdf", "resource": { "name": "ACME Inc.", "elements": [ "acme_records" ] } }]modules/acme_records/acme_records.detail.json
{ "tabs": [ { "identifier": "general", "rows": [ { "cols": [ { "span": 24, "components": [ { "type": "field_group", "identifier": "general", "options": { "fields": [ "name", "content" ] } }, { "type": "buttons", "identifier": "export", "options": { "buttons": [ { "identifier": "acme_export_record", "title": "buttons.acme_export_record", "style": "primary", "event": { "action": "workflow", "event": "acme_export_record", "module": "acme_records" } } ] } } ] } ] } ] } ]}modules/acme_records/acme_records.index.json
{ "tabs": [ { "identifier": "general", "rows": [ { "cols": [ { "span": 24, "components": [ { "type": "resource_table", "identifier": "records", "options": { "module": "acme_records" } } ] } ] } ] } ]}modules/acme_records/acme_records.module.bake.json
[ { "resource_module": "acme_records", "resource": { "identifier": "acme_records", "title": "name", "fields": [ { "identifier": "name", "type": "text" }, { "identifier": "content", "type": "textarea" } ], "layouts": { "detail": "/modules/acme_records/acme_records.detail", "index": "/modules/acme_records/acme_records.index" } } }]preview/sample.bake.json
[ { "resource_entity": "acme_preview_record", "resource": { "module": "acme_records", "fields": { "name": "ACME Inc. record", "content": "Example record for preview." } } }]tests/acme_record_download.test.workflow.json
{ "identifier": "acme_record_download", "workflow": "acme_record_pdf", "fixtures": [ { "type": "entity", "module": "acme_records", "alias": "record", "fields": { "name": "ACME Test Record", "content": "Example content <safe>" } } ], "trigger": { "type": "dispatch_sync", "entry": "acme_export_record", "data": { "prototype": "fixture:record" } }, "assertions": [ { "type": "download_offered", "filename_contains": "acme-record.pdf" }, { "type": "entity_exists", "module": "files", "where": { "name": "acme-record.pdf", "mime_type": "application/pdf" } } ]}translations/de.json
{ "modules": { "acme_records": { "title": "Dokumente", "fields": { "name": "Name", "content": "Inhalt" }, "tabs": { "general": "Allgemein" } } }, "buttons": { "acme_export_record": "PDF erzeugen" }}translations/en.json
{ "modules": { "acme_records": { "title": "Records", "fields": { "name": "Name", "content": "Content" }, "tabs": { "general": "General" } } }, "buttons": { "acme_export_record": "Generate PDF" }}translations/translations.bake.json
[ { "resource_translations": "de", "resource": { "identifier": "de", "code": "de_DE", "name": "Deutsch", "dir": "ltr", "provider": "deDE", "data": "${file('translations/de.json')}" } }, { "resource_translations": "en", "resource": { "identifier": "en", "code": "en_US", "name": "English", "dir": "ltr", "provider": "enUS", "data": "${file('translations/en.json')}" } }]views/record.twig
{% block header %}<html><body><strong>ACME Inc.</strong></body></html>{% endblock %}{% block content %}<html><body><h1>{{ record.name|e }}</h1><p>{{ record.content|e }}</p></body></html>{% endblock %}{% block footer %}<html><body>ACME Inc. — record export</body></html>{% endblock %}views/record.view.bake.json
[ { "resource_view": "acme_record_pdf", "resource": { "module": "views", "fields": { "name": "acme_record_pdf", "type": "twig", "code": "${file('views/record.twig')}" } } }]workflows/acme_record_pdf.workflow.bake.json
[ { "resource_workflow": "acme_record_pdf", "resource": { "identifier": "acme_record_pdf", "title": "ACME Inc. — acme_record_pdf", "active": true, "async": false, "entry": "acme_export_record", "elements": [ { "name": "acme_export_record", "type": "event/webhook", "options": { "module": "acme_records", "public": false }, "set": { "record": "prototype:" }, "to": { "default": { "makePdf": [ "default" ] } } }, { "name": "makePdf", "type": "action/export", "options": { "type": "pdf", "view": "acme_record_pdf", "filename": "acme-record.pdf", "view_data": { "record": "$record" } }, "in": { "default": "$record" }, "to": { "default": { "download": [ "default" ] } } }, { "name": "download", "type": "action/downloadFile", "options": {}, "to": {} } ], "events": [ { "identifier": "acme_export_record", "type": "webhook", "module": "acme_records" } ] } }]Source: brezel/api@572da72238ad1aab7b60287c898eaede2c08a876
Agents: system_authoring_command reference kind=feature query=acme_record_pdf
How it works
Section titled “How it works”The button uses title, style and event: {action: "workflow", module, event}. The graph entry and events[] registration use the same event identifier. async: false lets action/downloadFile return the file response. One named Twig view supplies header/content/footer blocks to action/export through view.
Test it
Section titled “Test it”Copy the example files relative to your system root. Merge existing native modules, menus and roles; rename all related identifiers together. Apply preview data only in a disposable preview. Run the plan, apply and tests against that preview:
php bakery plan <system>php bakery apply <system>php bakery system test-run <system>acme_record_download binds a saved fixture to the webhook and asserts download_offered. That checks Content-Disposition, not PDF validity. The upstream PHPUnit test separately checks rendered blocks with a fake PDF transport. Production needs brezel.export.url; test a real PDF and its page layout there.
Other ways
Section titled “Other ways”- Recommended for printing a record without workflow logic: module
print_view. Its exact reference syntax remains unverified; check it before applying. - Recommended for Word-authored templates:
action/renderDocxthenaction/convert. The complete PDF conversion chain remains unverified. - Recommended for physical printer output:
action/printthrough CUPS; it is not the PDF-download path. - Not recommended: direct
content,header,footerorpage_setupaction/export options. They are ignored. Use the single view’s Twig blocks, with an optional JSONsetupblock.
Reference
Section titled “Reference”Buttons schema · Export · UI integration · Workflow tests · Assertions