protected static function ResourceResponseSubscriber::generateContext in Drupal 8
Same name and namespace in other branches
- 9 core/modules/jsonapi/src/EventSubscriber/ResourceResponseSubscriber.php \Drupal\jsonapi\EventSubscriber\ResourceResponseSubscriber::generateContext()
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 core/
modules/ jsonapi/ src/ EventSubscriber/ ResourceResponseSubscriber.php - Renders a resource response body.
File
- core/
modules/ jsonapi/ 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;
}