Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions content/collections/pages/build-a-fieldtype.md
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,25 @@ Text::appendConfigFields([
]);
```

You may also append an entire section of fields, rather than a single field, by passing an array without a string key. It should have a `display` and `fields`, just like a regular blueprint section.

```php
Text::appendConfigFields([
[
'display' => 'Extra section',
'fields' => [
'more_options' => [
'type' => 'array',
'display' => 'Options',
'instructions' => 'Instructions for this field',
],
],
],
]);
```

You may mix fields and sections in the same call. Anything with a string key will be treated as a single field, while anything without one will be treated as a section.

You can also append a config field to _all_ fieldtypes via the `Fieldtype` class:

```php
Expand Down
2 changes: 2 additions & 0 deletions content/collections/pages/collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ To use modifiers in title formats, make sure to use the `{{` Antlers syntax, lik
```
:::

As you fill in the fields referenced by your title format, the entry's title (and therefore its slug) will update live in the Control Panel — you don't need to save first to see them.

## Slugs

Slugs are used in entry URLs. For an entry named `My Entry`, the slug would default to `my-entry` unless you edit it.
Expand Down
9 changes: 9 additions & 0 deletions content/collections/pages/conditional-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@ if_any:
that_field: cheeseburger
```

You may also define multiple conditions against the *same* field by providing an array of conditions. For example, the following will show the field when `age` is greater than `18` *__AND__* less than `65`:

```yaml
if:
age:
- '> 18'
- '< 65'
```

## Nested fields

You may use dot notation to access nested values when necessary. For example, maybe you would like to show a field when an `array` fieldtype's `country` value is `Canada`:
Expand Down
9 changes: 9 additions & 0 deletions content/collections/pages/dictionaries.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ class States extends BasicDictionary

In the example above, you can see that each item has a `label` and `value`. These will be used in the dropdown field. Any additional keys will be available within templates.

You may also provide an `icon`, which will be displayed alongside the item's label in the fieldtype:

```php
['label' => 'Alabama', 'value' => 'AL', 'capital' => 'Montgomery', 'icon' => 'map-pin'],
```

The `icon` may be the name of one of Statamic's built-in icons, or an inline SVG string. Like `label`, it will not be available within templates, and won't be considered when [searching](#basic-search).

Here we are returning a hardcoded array. But in reality you may be getting options from somewhere like a file, database, or an API:

```php
Expand Down Expand Up @@ -145,6 +153,7 @@ public function get(string $key): ?Item
return new Item($key, $product->name, [
'price' => $product->price,
'sku' => $product->sku,
'icon' => 'tag',
]);
}
```
Expand Down
7 changes: 7 additions & 0 deletions content/collections/pages/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,13 @@ public function handle(CollectionTreeSaving $event)
}
```

You may suppress the `CollectionTreeSaving`, `CollectionTreeSaved`, and `CollectionTreeDeleted` events by using the `saveQuietly` and `deleteQuietly` methods on the tree, instead of `save` and `delete`.

``` php
$tree->saveQuietly();
$tree->deleteQuietly();
```

### EntryBlueprintFound
`Statamic\Events\EntryBlueprintFound`

Expand Down
204 changes: 201 additions & 3 deletions content/collections/pages/rest-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ https://yourdomain.tld/api/{endpoint}
`
You may send requests to the following endpoints:

- [Ping](#ping)
- [Sites](#sites)
- [Collections](#collections) / [Collection](#collection)
- [Entries](#entries) / [Entry](#entry)
- [Collection Tree](#collection-tree) / [Navigation Tree](#navigation-tree)
- [Navs](#navs) / [Nav](#nav)
- [Taxonomies](#taxonomies) / [Taxonomy](#taxonomy)
- [Taxonomy Terms](#taxonomy-terms) / [Taxonomy Term](#taxonomy-term)
- [Asset Containers](#asset-containers) / [Asset Container](#asset-container)
- [Assets](#assets) / [Asset](#asset)
- [Globals](#globals) / [Global](#global)
- [Forms](#forms) / [Form](#form)
Expand Down Expand Up @@ -218,6 +224,14 @@ You may specify which top level fields should be included in the response.
/endpoint?fields=id,title,content
```

You may also use array syntax:

``` url
/endpoint?fields[]=id&fields[]=title&fields[]=content
```

On the [Entry](#entry) and [Asset](#asset) endpoints, `fields` will also be honored when fetching a single item, not just when listing them.

## Pagination

Results will be paginated into 25 items per page by default. You may specify the items per page and which page you are viewing with the `limit` and `page` parameters:
Expand Down Expand Up @@ -253,6 +267,84 @@ The response will contain your `data`, `links` to easily get next/previous URLs,

---

## Ping

`GET` `/api/ping`

A simple health check endpoint. It returns `pong`, and is available whenever the REST API is enabled, regardless of which resources are enabled.

``` json
{
"ping": "pong"
}
```

## Sites

`GET` `/api/sites`

Gets all configured sites. This resource is disabled by default. You can enable it with `resources.sites` in your `config/statamic/api.php` config:

```php
'resources' => [
'sites' => true,
],
```

``` json
{
"data": [
{
"handle": "default",
"name": "Default",
"locale": "en_US",
"short_locale": "en",
"url": "http://example.com/"
}
]
}
```

## Collections

`GET` `/api/collections`

Gets all collections.

``` json
{
"data": [
{
"handle": "blog",
"title": "Blog",
"structure": null,
"mount": "9412926e-8d33-4f83-8db9-72cbc4c69bcf",
"api_url": "http://example.com/api/collections/blog"
}
]
}
```

## Collection

`GET` `/api/collections/{collection}`

Gets a single collection.

``` json
{
"data": {
"handle": "blog",
"title": "Blog",
"structure": null,
"mount": "9412926e-8d33-4f83-8db9-72cbc4c69bcf",
"api_url": "http://example.com/api/collections/blog"
}
}
```

If the collection is structured, `structure` will contain its `max_depth` and `expects_root` values instead of `null`.

## Entries

`GET` `/api/collections/{collection}/entries`
Expand All @@ -272,15 +364,15 @@ Gets entries within a collection.
```

:::tip
If you are using [Multi-Site](/multi-site), the entries endpoint will serve from all sites at once. If needed, you can limit the fetched data to a specific site with a `site` [filter](#filtering) (ie. `&filter[site]=fr`).
If you are using [Multi-Site](/multi-site), the entries endpoint will serve from all sites at once. If needed, you can limit the fetched data to a specific site with the `site` query parameter (ie. `?site=fr`), or a `site` [filter](#filtering) (ie. `&filter[site]=fr`).
:::


## Entry

`GET` `/api/collections/{collection}/entries/{id}`

Gets a single entry.
Gets a single entry by ID or slug. If both an ID and a slug match, the entry matched by ID takes priority. When resolving by slug on a multi-site collection, the `site` query parameter will be used if provided, otherwise the collection's first configured site will be used.

``` json
{
Expand Down Expand Up @@ -330,6 +422,44 @@ On this endpoint, the [fields](#selecting-fields) param will allow you to select
```


## Navs

`GET` `/api/navs`

Gets all navigations.

``` json
{
"data": [
{
"handle": "main",
"title": "Main Navigation",
"max_depth": null,
"expects_root": false,
"api_url": "http://example.com/api/navs/main"
}
]
}
```

## Nav

`GET` `/api/navs/{nav}`

Gets a single navigation.

``` json
{
"data": {
"handle": "main",
"title": "Main Navigation",
"max_depth": null,
"expects_root": false,
"api_url": "http://example.com/api/navs/main"
}
}
```

## Navigation Tree

`GET` `/api/navs/{nav}/tree`
Expand Down Expand Up @@ -369,6 +499,40 @@ On this endpoint, the [fields](#selecting-fields) param will allow you to select
```


## Taxonomies

`GET` `/api/taxonomies`

Gets all taxonomies.

``` json
{
"data": [
{
"handle": "tags",
"title": "Tags",
"api_url": "http://example.com/api/taxonomies/tags"
}
]
}
```

## Taxonomy

`GET` `/api/taxonomies/{taxonomy}`

Gets a single taxonomy.

``` json
{
"data": {
"handle": "tags",
"title": "Tags",
"api_url": "http://example.com/api/taxonomies/tags"
}
}
```

## Taxonomy Terms

`GET` `/api/taxonomies/{taxonomy}/terms`
Expand All @@ -388,7 +552,7 @@ Gets terms in a taxonomy.
```

:::tip
If you are using [Multi-Site](/multi-site), you can select the site using a `site` [filter](#filtering) (ie. `&filter[site]=fr`).
If you are using [Multi-Site](/multi-site), you can select the site using the `site` query parameter (ie. `?site=fr`), or a `site` [filter](#filtering) (ie. `&filter[site]=fr`).
:::

## Taxonomy term
Expand Down Expand Up @@ -536,6 +700,40 @@ Get a single user.
}
```

## Asset Containers

`GET` `/api/asset-containers`

Gets all asset containers. This uses the same `resources.assets` config as the [Assets](#assets) endpoint.

``` json
{
"data": [
{
"handle": "main",
"title": "Main",
"api_url": "http://example.com/api/asset-containers/main"
}
]
}
```

## Asset Container

`GET` `/api/asset-containers/{container}`

Gets a single asset container.

``` json
{
"data": {
"handle": "main",
"title": "Main",
"api_url": "http://example.com/api/asset-containers/main"
}
}
```

## Assets

`GET` `/api/assets/{container}`
Expand Down
Loading