Merge pull request #17568 from agileware/CIVICRM-1496
[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": "",
16 "is_public": false,
17 "server_route": "civicrm/hello-world",
18 "layout": {
19 "#tag": "div",
20 "#children": [
21 "Hello {{routeParams.name}}"
22 ]
23 },
24 }
8a0ffdf9
TO
25}
26```
27
28Additionally, you can also update the forms:
29
30```
4f4b6487 31$ cv api4 afform.update +w name=helloWorld +v title="The Foo Bar Screen"
8a0ffdf9 32{
a00d9bd3 33 "0": {
4f4b6487 34 "name": "helloWorld",
8a0ffdf9
TO
35 "title": "The Foo Bar Screen"
36 }
37}
38```
39
40A few important things to note about this:
41
42* The changes made through the API are only applied on this site.
43* Once you make a change with the CRUD API, there will be two copies of the form:
4f4b6487
TO
44 * `[myextension]/ang/helloWorld.aff.html` is the default, canonical version.
45 * `[civicrm.files]/ang/helloWorld.aff.html` is the local, custom version.
46* The `layout` field is stored as an Angular-style HTML document (`helloWorld.aff.html`), so you can edit it on disk like
8a0ffdf9 47 normal Angular code. However, when CRUD'ing the `layout` through the API, it is presented in JSON-style.
4f4b6487
TO
48
49To undo the change, you can use the `revert` API. This will remove any local overrides so that the canonical content
50(`[myextension]/ang/helloWorld.aff.html`) is activated.
51
52```
53$ cv api4 afform.revert +w name=helloWorld
54```