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
42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ The query string param name that should be used to identify which page is being

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

### `resourceKey`
#### `resourceKey`

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

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

#### `includes`

The [include names](http://fractal.thephpleague.com/transformers/#including-data) that should be included for the current request, if any.

```php
'includes' => craft()->request->getQuery('include'),
```

Note that this setting requires a custom transformer class that’s prepped to handle includes:

```php
class MyTransformerClassName extends TransformerAbstract
{
protected $availableIncludes = ['author'];

public function includeAuthor(EntryModel $entry)
{
return $this->item($entry->author, function(UserModel($author) {
return [
'id' => $author->id,
'name' => $author->name,
];
});
}

// ...
}
```

#### `excludes`


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.

```php
'excludes' => 'author',
```

Like [`includes`](#includes), this setting requires a custom transformer class.

#### `jsonOptions`

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 no options will be passed.
Expand Down
8 changes: 8 additions & 0 deletions elementapi/controllers/ElementApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ public function actionGetElements($configFactory = null, array $config = null)
}
$fractal->setSerializer($serializer);

// Set the includes
$includes = isset($config['includes']) ? $config['includes'] : [];
$fractal->parseIncludes($includes);

// Set the excludes
$excludes = isset($config['excludes']) ? $config['excludes'] : [];
$fractal->parseExcludes($excludes);

// Define the transformer
if (is_callable($config['transformer']) || $config['transformer'] instanceof TransformerAbstract)
{
Expand Down