You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+56-6
Original file line number
Diff line number
Diff line change
@@ -12,12 +12,14 @@
12
12
13
13
This library provides an API client so that you can read and write your document type definitions using the [Prismic Custom Types API](https://prismic.io/docs/technologies/custom-types-api).
14
14
15
-
Currently, you can list, read, insert and update document types.
15
+
Currently, you can list, read, insert and update document types, and do the same for 'Shared Slices'
16
16
17
-
The client requires that you make use of _(And similarly, it returns instances of)_ the shipped `Definition` value object.
17
+
The client requires that you make use of _(And similarly, it returns instances of)_ the shipped `Definition`or `SharedSlice`value objects.
18
18
19
19
Typically, you wouldn't interact with the client directly, but as part of a build process that takes care of all that stuff for you. This client is quite fresh, but it's primary use will soon be part of [`netglue/prismic-cli`](https://github.com/netglue/prismic-cli), so that it will become trivial to synchronise your local development document definitions with those in your production Prismic repository _(and vice-versa)_.
20
20
21
+
It's worth noting that document types and slices are not validated in any way. That's up to you, but, you should get descriptive exceptions when your JSON doesn't validate on the remote server.
22
+
21
23
## Installation
22
24
23
25
The only supported installation method is via composer:
@@ -44,16 +46,64 @@ $client = new BaseClient(
44
46
)
45
47
```
46
48
49
+
## Usage
50
+
51
+
### CRUD for Document Types
52
+
53
+
```php
54
+
use Prismic\DocumentType\Client;
55
+
use Prismic\DocumentType\Definition;
56
+
57
+
assert($client instanceof Client);
58
+
59
+
// Insert or update a document type:
60
+
$client->saveDefinition(Definition::new(
61
+
id: 'my-type',
62
+
label: 'Some Label',
63
+
repeatable: true,
64
+
active: true,
65
+
json: $someJsonPayloadAsAString,
66
+
));
67
+
68
+
// Fetch all remote document type defs
69
+
$client->fetchAllDefinitions();
70
+
71
+
// Fetch a single definition
72
+
$client->getDefinition('some-type');
73
+
74
+
// Delete a document type definition
75
+
$client->deleteDefinition('some-type');
76
+
```
77
+
78
+
### CRUD for Shared Slices
79
+
80
+
```php
81
+
use Prismic\DocumentType\SharedSlice;use Prismic\DocumentType\SharedSliceManagementClient;
Currently, authentication is only possible with a [permanent access token](https://prismic.io/docs/technologies/custom-types-api#permanent-token-recommended) that you create/retrieve from the Prismic repository settings. Session based tokens are not supported.
52
106
53
-
### Slices
54
-
55
-
CRUD operations on shared slices are not yet implemented but are planned for future development. If you really want this feature, you're welcome to contribute.
56
-
57
107
## Contributing
58
108
59
109
Please feel free to get involved with development. The project uses PHPUnit for tests, [Psalm](https://psalm.dev) for static analysis and [Infection](https://infection.github.io) for mutation testing. CI should have your back if you want to submit a feature or fix ;)
0 commit comments