You are here

public function MongodbWatchdogServiceProvider::alter in MongoDB 8.2

Modifies existing service definitions.

Parameters

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

Overrides ServiceModifierInterface::alter

File

modules/mongodb_watchdog/src/MongodbWatchdogServiceProvider.php, line 23

Class

MongodbWatchdogServiceProvider
MongodbWatchdogServiceProvider add $formState support to forms.

Namespace

Drupal\mongodb_watchdog

Code

public function alter(ContainerBuilder $container) {
  $kernelResolverDefinition = $container
    ->getDefinition(static::KERNEL_RESOLVER);
  $resolvers = $kernelResolverDefinition
    ->getArgument(1);
  $defaultIndex = $count = count($resolvers);

  /** @var \Symfony\Component\DependencyInjection\Reference $reference */
  foreach ($resolvers as $index => $reference) {
    if ("{$reference}" === static::RESOLVER_DEFAULT) {
      $defaultIndex = $index;
      break;
    }
  }
  $formStateResolverReference = new Reference(static::RESOLVER_FORM_STATE);

  // If the default resolved is present, insert just before it.
  if ($defaultIndex != $count) {
    array_splice($resolvers, $defaultIndex, 0, [
      $formStateResolverReference,
    ]);
  }
  else {
    array_push($resolvers, [
      $formStateResolverReference,
    ]);
  }
  $kernelResolverDefinition
    ->setArgument(1, $resolvers);
}