You are here

public function JsonapiServiceProvider::alter in JSON:API 8

Same name and namespace in other branches
  1. 8.2 src/JsonapiServiceProvider.php \Drupal\jsonapi\JsonapiServiceProvider::alter()

Modifies existing service definitions.

Parameters

ContainerBuilder $container: The ContainerBuilder whose service definitions can be altered.

Overrides ServiceModifierInterface::alter

File

src/JsonapiServiceProvider.php, line 22

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(), '\\Drupal\\Core\\StackMiddleware\\NegotiationMiddleware', 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',
      ],
    ]);
  }
}