function JsonapiServiceProvider::alter

Same name in other branches
  1. 9 core/modules/jsonapi/src/JsonapiServiceProvider.php \Drupal\jsonapi\JsonapiServiceProvider::alter()
  2. 10 core/modules/jsonapi/src/JsonapiServiceProvider.php \Drupal\jsonapi\JsonapiServiceProvider::alter()
  3. 11.x core/modules/jsonapi/src/JsonapiServiceProvider.php \Drupal\jsonapi\JsonapiServiceProvider::alter()

Overrides ServiceModifierInterface::alter

File

core/modules/jsonapi/src/JsonapiServiceProvider.php, line 25

Class

JsonapiServiceProvider
Adds 'api_json' as known format and prevents its use in the REST module.

Namespace

Drupal\jsonapi

Code

public function alter(ContainerBuilder $container) {
    if ($container->has('http_middleware.negotiation') && is_a($container->getDefinition('http_middleware.negotiation')
        ->getClass(), NegotiationMiddleware::class, TRUE)) {
        // @see http://www.iana.org/assignments/media-types/application/vnd.api+json
        $container->getDefinition('http_middleware.negotiation')
            ->addMethodCall('registerFormat', [
            'api_json',
            [
                'application/vnd.api+json',
            ],
        ]);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.