Merge pull request #18779 from jaapjansma/dev_report_53
[civicrm-core.git] / ext / afform / docs / crud.md
CommitLineData
64423b13 1# Form CRUD: Updating forms via programmatic API
8a0ffdf9
TO
2
3Now that we've defined a baseline form, it's possible for administrators and
4GUI applications to inspect the form using the API:
5
6```
4f4b6487 7$ cv api4 afform.get +w name=helloWorld
8a0ffdf9 8{
a00d9bd3 9 "0": {
4f4b6487 10 "name": "helloWorld",
a00d9bd3 11 "requires": [
c1b9955f 12 "afCore"
a00d9bd3
TO
13 ],
14 "title": "",
15 "description": "",
1887d8bd 16 "is_dashlet": false,
a00d9bd3
TO
17 "is_public": false,
18 "server_route": "civicrm/hello-world",
19 "layout": {
20 "#tag": "div",
21 "#children": [
22 "Hello {{routeParams.name}}"
23 ]
24 },
25 }
8a0ffdf9
TO
26}
27```
28
29Additionally, you can also update the forms:
30
31```
4f4b6487 32$ cv api4 afform.update +w name=helloWorld +v title="The Foo Bar Screen"
8a0ffdf9 33{
a00d9bd3 34 "0": {
4f4b6487 35 "name": "helloWorld",
8a0ffdf9
TO
36 "title": "The Foo Bar Screen"
37 }
38}
39```
40
41A few important things to note about this:
42
43* The changes made through the API are only applied on this site.
44* Once you make a change with the CRUD API, there will be two copies of the form:
4f4b6487
TO
45 * `[myextension]/ang/helloWorld.aff.html` is the default, canonical version.
46 * `[civicrm.files]/ang/helloWorld.aff.html` is the local, custom version.
47* The `layout` field is stored as an Angular-style HTML document (`helloWorld.aff.html`), so you can edit it on disk like
8a0ffdf9 48 normal Angular code. However, when CRUD'ing the `layout` through the API, it is presented in JSON-style.
4f4b6487
TO
49
50To undo the change, you can use the `revert` API. This will remove any local overrides so that the canonical content
51(`[myextension]/ang/helloWorld.aff.html`) is activated.
52
53```
54$ cv api4 afform.revert +w name=helloWorld
55```