function ResourceResponseSubscriber::generateContext
Same name in other branches
- 9 core/modules/jsonapi/src/EventSubscriber/ResourceResponseSubscriber.php \Drupal\jsonapi\EventSubscriber\ResourceResponseSubscriber::generateContext()
- 10 core/modules/jsonapi/src/EventSubscriber/ResourceResponseSubscriber.php \Drupal\jsonapi\EventSubscriber\ResourceResponseSubscriber::generateContext()
- 11.x 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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.