public function EntityResource::getIncludes in JSON:API Extras 8.3
Gets includes for the given response data.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The request object.
\Drupal\jsonapi\JsonApiResource\ResourceObject|\Drupal\jsonapi\JsonApiResource\ResourceObjectData $data: The response data from which to resolve includes.
Return value
\Drupal\jsonapi\JsonApiResource\Data A Data object to be included or a NullData object if the request does not specify any include paths.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
Overrides EntityResource::getIncludes
File
- modules/
jsonapi_defaults/ src/ Controller/ EntityResource.php, line 101
Class
- EntityResource
- Overrides jsonapi module EntityResource controller.
Namespace
Drupal\jsonapi_defaults\ControllerCode
public function getIncludes(Request $request, $data) {
/** @var \Drupal\jsonapi_extras\ResourceType\ConfigurableResourceType $resourceConfig */
if (($resource_type = $request
->get(Routes::RESOURCE_TYPE_KEY)) && $resource_type instanceof ConfigurableResourceType && !$request
->get('_on_relationship')) {
try {
$resource_type = static::correctResourceTypeOnRelated($request
->get('related'), $resource_type);
} catch (\LengthException $e) {
watchdog_exception('jsonapi_defaults', $e);
return parent::getIncludes($request, $data);
}
if (!$resource_type instanceof ConfigurableResourceType) {
return parent::getIncludes($request, $data);
}
$resource_config = $resource_type
->getJsonapiResourceConfig();
if (!$resource_config instanceof JsonapiResourceConfig) {
return parent::getIncludes($request, $data);
}
$default_includes = $resource_config
->getThirdPartySetting('jsonapi_defaults', 'default_include', []);
if (!empty($default_includes) && $request->query
->get('include') === NULL) {
$includes = array_unique(array_filter(array_merge($default_includes, explode(',', $request->query
->get('include', '')))));
$request->query
->set('include', implode(',', $includes));
}
}
return parent::getIncludes($request, $data);
}