JsonapiServiceProvider.php in JSON:API 8.2
File
src/JsonapiServiceProvider.php
View source
<?php
namespace Drupal\jsonapi;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceModifierInterface;
use Drupal\Core\DependencyInjection\ServiceProviderInterface;
use Drupal\Core\StackMiddleware\NegotiationMiddleware;
use Drupal\jsonapi\DependencyInjection\Compiler\RegisterSerializationClassesCompilerPass;
use Symfony\Component\DependencyInjection\Reference;
class JsonapiServiceProvider implements ServiceModifierInterface, ServiceProviderInterface {
public function alter(ContainerBuilder $container) {
if (floatval(\Drupal::VERSION) < 8.6) {
$definition = $container
->getDefinition('jsonapi.resource_type.repository');
$definition
->setArgument(3, new Reference('cache.static'));
$container
->setDefinition('jsonapi.resource_type.repository', $definition);
$container
->removeDefinition('cache.jsonapi_resource_types');
}
if ($container
->has('http_middleware.negotiation') && is_a($container
->getDefinition('http_middleware.negotiation')
->getClass(), NegotiationMiddleware::class, TRUE)) {
$container
->getDefinition('http_middleware.negotiation')
->addMethodCall('registerFormat', [
'api_json',
[
'application/vnd.api+json',
],
])
->addMethodCall('registerFormat', [
'bin',
[
'application/octet-stream',
],
]);
}
if (floatval(\Drupal::VERSION) < 8.6) {
$container
->removeDefinition('jsonapi.file_upload');
$container
->removeDefinition('file.uploader');
}
}
public function register(ContainerBuilder $container) {
$container
->addCompilerPass(new RegisterSerializationClassesCompilerPass());
}
}