GraphqlTwigServiceProvider::alter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\graphql_twig;
4
5
use Drupal\Core\DependencyInjection\ContainerBuilder;
6
use Drupal\Core\DependencyInjection\ServiceProviderBase;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
/**
10
 * Service provider to inject a custom derivation of `TwigEnvironment`.
11
 */
12
class GraphqlTwigServiceProvider extends ServiceProviderBase {
13
14
  /**
15
   * {@inheritdoc}
16
   */
17
  public function alter(ContainerBuilder $container) {
18
    // Replace the twig environment with the GraphQL enhanced one.
19
    $container->getDefinition('twig')
20
      ->setClass(GraphQLTwigEnvironment::class)
21
      ->addArgument(new Reference('graphql.query_processor'))
22
      ->addArgument(new Reference('renderer'));
23
24
    // Inject our own argument resolver.
25
    $def = $container->getDefinition('http_kernel.controller.argument_resolver');
26
    $argumentResolvers = $def->getArgument(1);
27
    $argumentResolvers[] = new Reference('argument_resolver.graphql_twig');
28
    $def->setArgument(1, $argumentResolvers);
29
  }
30
31
}
32