Skip to content

Commit

Permalink
[4.x] REST API Globals return resolved relations (#8555)
Browse files Browse the repository at this point in the history
Co-authored-by: Jason Varga <jason@pixelfear.com>
  • Loading branch information
martink635 and jasonvarga authored Aug 9, 2023
1 parent 1ddff9b commit 3bd7708
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/Http/Resources/API/GlobalSetResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

class GlobalSetResource extends JsonResource
{
/** @deprecated */
private static $relations = false;

/**
* Transform the resource into an array.
*
Expand All @@ -15,13 +18,29 @@ class GlobalSetResource extends JsonResource
*/
public function toArray($request)
{
return $this->resource
$collection = $this->resource
->toAugmentedCollection()
->merge([
'handle' => $this->resource->handle(),
'api_url' => Statamic::apiRoute('globals.show', [$this->resource->handle()]),
])
]);

if (static::$relations) {
$with = $this->resource->blueprint()
->fields()->all()
->filter->isRelationship()->keys()->all();

$collection->withRelations($with);
}

return $collection
->withShallowNesting()
->toArray();
}

/** @deprecated */
public static function withRelations()
{
static::$relations = true;
}
}

0 comments on commit 3bd7708

Please sign in to comment.