You are here

class MongodbWatchdogServiceProvider in MongoDB 8.2

MongodbWatchdogServiceProvider add $formState support to forms.

Hierarchy

Expanded class hierarchy of MongodbWatchdogServiceProvider

File

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

Namespace

Drupal\mongodb_watchdog
View source
class MongodbWatchdogServiceProvider implements ServiceModifierInterface {
  const KERNEL_RESOLVER = 'http_kernel.controller.argument_resolver';

  // Individual resolvers.
  const RESOLVER_DEFAULT = 'argument_resolver.default';
  const RESOLVER_FORM_STATE = 'argument_resolver.mongodb_watchdog.form_state';

  /**
   * {@inheritdoc}
   */
  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);
  }

}

Members