HalServiceProvider.php 685 B

12345678910111213141516171819202122
  1. <?php
  2. namespace Drupal\hal;
  3. use Drupal\Core\DependencyInjection\ContainerBuilder;
  4. use Drupal\Core\DependencyInjection\ServiceModifierInterface;
  5. /**
  6. * Adds hal+json as known format.
  7. */
  8. class HalServiceProvider implements ServiceModifierInterface {
  9. /**
  10. * {@inheritdoc}
  11. */
  12. public function alter(ContainerBuilder $container) {
  13. if ($container->has('http_middleware.negotiation') && is_a($container->getDefinition('http_middleware.negotiation')->getClass(), '\Drupal\Core\StackMiddleware\NegotiationMiddleware', TRUE)) {
  14. $container->getDefinition('http_middleware.negotiation')->addMethodCall('registerFormat', ['hal_json', ['application/hal+json']]);
  15. }
  16. }
  17. }