protected static function ResourceResponseSubscriber::generateContext in JSON:API 8.2
Generates a top-level JSON:API normalization context.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The request from which the context can be derived.
Return value
array The generated context.
1 call to ResourceResponseSubscriber::generateContext()
- ResourceResponseSubscriber::renderResponseBody in src/
EventSubscriber/ ResourceResponseSubscriber.php - Renders a resource response body.
File
- src/
EventSubscriber/ ResourceResponseSubscriber.php, line 141
Class
- ResourceResponseSubscriber
- Response subscriber that serializes and removes ResourceResponses' data.
Namespace
Drupal\jsonapi\EventSubscriberCode
protected static function generateContext(Request $request) {
// Build the expanded context.
$context = [
'account' => NULL,
'sparse_fieldset' => NULL,
];
if ($request->query
->get('fields')) {
$context['sparse_fieldset'] = array_map(function ($item) {
return explode(',', $item);
}, $request->query
->get('fields'));
}
return $context;
}