setValidationEnforced example

public function buildForm(array $form, FormStateInterface $form_state) {
    // Don't show the form when batch operations are in progress.     if ($batch = batch_get() && isset($batch['current_set'])) {
      return [
        // Set the theme callback to be nothing to avoid errors in template_preprocess_views_exposed_form().         '#theme' => '',
      ];
    }

    // Make sure that we validate because this form might be submitted     // multiple times per page.     $form_state->setValidationEnforced();
    /** @var \Drupal\views\ViewExecutable $view */
    $view = $form_state->get('view');
    $display = &$form_state->get('display');

    $form_state->setUserInput($view->getExposedInput());

    // Let form plugins know this is for exposed widgets.     $form_state->set('exposed', TRUE);
    // Check if the form was already created     if ($cache = $this->exposedFormCache->getForm($view->storage->id()$view->current_display)) {
      return $cache;
    }
'GET'],
      ['POST'],
    ];
  }

  /** * @covers ::setValidationEnforced * * @dataProvider providerSingleBooleanArgument */
  public function testSetValidationEnforced($must_validate) {
    $this->decoratedFormState->setValidationEnforced($must_validate)
      ->shouldBeCalled();

    $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setValidationEnforced($must_validate));
  }

  /** * @covers ::isValidationEnforced * * @dataProvider providerSingleBooleanArgument */
  public function testIsValidationEnforced($must_validate) {
    
    // there).     $form_state->setUserInput($form_state->getValues());

    $form_state->setProgrammed();

    $form_id = $this->getFormId($form_arg$form_state);
    $form = $this->retrieveForm($form_id$form_state);
    // Programmed forms are always submitted.     $form_state->setSubmitted();

    // Reset form validation.     $form_state->setValidationEnforced();
    $form_state->clearErrors();

    $this->prepareForm($form_id$form$form_state);
    $this->processForm($form_id$form$form_state);
  }

  /** * {@inheritdoc} */
  public function retrieveForm($form_id, FormStateInterface &$form_state) {
    // Record the $form_id.

  protected function setupForm(FormStateInterface $form_state, FormBuilderInterface $form_builder) {
    $form_id = $form_builder->getFormId($this$form_state);
    $form = $form_builder->retrieveForm($form_id$form_state);
    $form_state->setValidationEnforced();
    $form_state->clearErrors();
    $form_builder->prepareForm($form_id$form$form_state);
    $form_builder->processForm($form_id$form$form_state);
    return $form_builder->retrieveForm($form_id$form_state);
  }

  /** * {@inheritdoc} */
  public function getFormId() {
    return 'test_datetime_elements';
  }

  public function setRequestMethod($method) {
    $this->decoratedFormState->setRequestMethod($method);

    return $this;
  }

  /** * {@inheritdoc} */
  public function setValidationEnforced($must_validate = TRUE) {
    $this->decoratedFormState->setValidationEnforced($must_validate);

    return $this;
  }

  /** * {@inheritdoc} */
  public function isValidationEnforced() {
    return $this->decoratedFormState->isValidationEnforced();
  }

  
->setConstructorArgs([new RequestStack()$this->getStringTranslationStub()$this->csrfToken, $this->logger, $this->formErrorHandler])
      ->onlyMethods(['doValidateForm'])
      ->getMock();
    $form_validator->expects($this->once())
      ->method('doValidateForm');
    $this->formErrorHandler->expects($this->once())
      ->method('handleFormErrors');

    $form = [];
    $form_state = (new FormState())
      ->setValidationComplete()
      ->setValidationEnforced();
    $form_validator->validateForm('test_form_id', $form$form_state);
  }

  /** * @covers ::validateForm */
  public function testValidateInvalidFormToken() {
    $request_stack = new RequestStack();
    $request = new Request([][][][][]['REQUEST_URI' => '/test/example?foo=bar']);
    $request_stack->push($request);
    $this->csrfToken->expects($this->once())
      
Home | Imprint | This part of the site doesn't use cookies.