Skip to content

Commit 7af75be

Browse files
committed
Merge branch 'v1' of github.com:pixelandtonic/ElementAPI into v2
# Conflicts: # CHANGELOG.md # elementapi/ElementApiPlugin.php # elementapi/controllers/ElementApiController.php # releases.json
2 parents 0a5587a + 336ef9f commit 7af75be

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ Changelog
5050
### Deprecated
5151
- Deprecated the `first` endpoint config setting. Use `one` instead.
5252

53+
## 1.6.0 - 2017-05-25
54+
55+
### Added
56+
- Added the `include` and `exclude` endpoint config settings. ([#41](https://github.com/craftcms/element-api/pull/41))
57+
5358
## 1.5.0 - 2017-05-24
5459

5560
### Added

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ The query string param name that should be used to identify which page is being
173173

174174
Note that it cannot be set to `'p'` because that’s the parameter Craft uses to check the requested path.
175175

176-
### `resourceKey`
176+
#### `resourceKey`
177177

178178
The key that the elements should be nested under in the response data. By default this will be `'data'`.
179179

@@ -203,6 +203,45 @@ Possible values are:
203203
- `'jsonFeed'` – formats data based on [JSON Feed V1](https://jsonfeed.org/version/1) (see the [JSON Feed](#json-feed) example below).
204204
- A custom serializer instance.
205205

206+
#### `includes`
207+
208+
The [include names](http://fractal.thephpleague.com/transformers/#including-data) that should be included for the current request, if any.
209+
210+
```php
211+
'includes' => craft()->request->getQuery('include'),
212+
```
213+
214+
Note that this setting requires a custom transformer class that’s prepped to handle includes:
215+
216+
```php
217+
class MyTransformerClassName extends TransformerAbstract
218+
{
219+
protected $availableIncludes = ['author'];
220+
221+
public function includeAuthor(EntryModel $entry)
222+
{
223+
return $this->item($entry->author, function(UserModel $author) {
224+
return [
225+
'id' => $author->id,
226+
'name' => $author->name,
227+
];
228+
});
229+
}
230+
231+
// ...
232+
}
233+
```
234+
235+
#### `excludes`
236+
237+
The [include names](http://fractal.thephpleague.com/transformers/#including-data) that should be excluded for the current request, which would otherwise have been included (e.g. if they were listed as a default include), if any.
238+
239+
```php
240+
'excludes' => 'author',
241+
```
242+
243+
Like [`includes`](#includes), this setting requires a custom transformer class.
244+
206245
#### `jsonOptions`
207246

208247
The value of the `$options` argument that will be passed to [`json_encode()`](http://php.net/manual/en/function.json-encode.php) when preparing the response. By default `JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE` will be passed.

0 commit comments

Comments
 (0)