You are here

class FormStateValueResolver in MongoDB 8.2

Yields a form_state argument for FormStateInterface $formState arguments.

This resolver supports form methods with a FormStateInterface argument regardless of its name.

Hierarchy

  • class \Drupal\mongodb_watchdog\Controller\ArgumentResolver\FormStateValueResolver implements \Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface

Expanded class hierarchy of FormStateValueResolver

1 string reference to 'FormStateValueResolver'
mongodb_watchdog.services.yml in modules/mongodb_watchdog/mongodb_watchdog.services.yml
modules/mongodb_watchdog/mongodb_watchdog.services.yml
1 service uses FormStateValueResolver
argument_resolver.mongodb_watchdog.form_state in modules/mongodb_watchdog/mongodb_watchdog.services.yml
Drupal\mongodb_watchdog\Controller\ArgumentResolver\FormStateValueResolver

File

modules/mongodb_watchdog/src/Controller/ArgumentResolver/FormStateValueResolver.php, line 16

Namespace

Drupal\mongodb_watchdog\Controller\ArgumentResolver
View source
class FormStateValueResolver implements ArgumentValueResolverInterface {
  const NAME_LEGACY = 'form_state';

  /**
   * {@inheritdoc}
   */
  public function supports(Request $request, ArgumentMetadata $argument) {
    $argumentInterfaceMatches = $argument
      ->getType() === FormStateInterface::class;
    $requestAttributeExists = $request->attributes
      ->has(static::NAME_LEGACY);
    return $argumentInterfaceMatches || $requestAttributeExists;
  }

  /**
   * {@inheritdoc}
   */
  public function resolve(Request $request, ArgumentMetadata $argument) {
    $formState = $request->attributes
      ->has(static::NAME_LEGACY) ? $request->attributes
      ->get(static::NAME_LEGACY) : NULL;
    (yield $formState);
  }

}

Members