setValidationComplete example

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

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

    return $this;
  }

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

  
call_user_func_array($form_state->prepareCallback($callback)[&$form, &$form_state]);
    }
  }

  /** * {@inheritdoc} */
  public function validateForm($form_id, &$form, FormStateInterface &$form_state) {
    // If this form is flagged to always validate, ensure that previous runs of     // validation are ignored.     if ($form_state->isValidationEnforced()) {
      $form_state->setValidationComplete(FALSE);
    }

    // If this form has completed validation, do not validate again.     if ($form_state->isValidationComplete()) {
      return;
    }

    // If the session token was set by self::prepareForm(), ensure that it     // matches the current user's session. This is duplicate to code in     // FormBuilder::doBuildForm() but left to protect any custom form handling     // code.

  public function testPreventDuplicateValidation() {
    $form_validator = $this->getMockBuilder('Drupal\Core\Form\FormValidator')
      ->setConstructorArgs([new RequestStack()$this->getStringTranslationStub()$this->csrfToken, $this->logger, $this->formErrorHandler])
      ->onlyMethods(['doValidateForm'])
      ->getMock();
    $form_validator->expects($this->never())
      ->method('doValidateForm');

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

  /** * Tests the 'must_validate' $form_state flag. * * @covers ::validateForm */
  public function testMustValidate() {
    $form_validator = $this->getMockBuilder('Drupal\Core\Form\FormValidator')
      
/** * @covers ::setValidationComplete * * @dataProvider providerSingleBooleanArgument * * @param bool $complete * Any valid value for * \Drupal\Core\Form\FormStateInterface::setValidationComplete()'s $complete * argument. */
  public function testSetValidationComplete($complete) {
    $this->decoratedFormState->setValidationComplete($complete)
      ->shouldBeCalled();

    $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setValidationComplete($complete));
  }

  /** * @covers ::isValidationComplete * * @dataProvider providerSingleBooleanArgument * * @param bool $complete * Any valid value for * \Drupal\Core\Form\FormStateInterface::isValidationComplete()'s return * value. */
      [[][]],
    ];
  }

  /** * Tests that form errors during submission throw an exception. * * @covers ::setErrorByName */
  public function testFormErrorsDuringSubmission() {
    $form_state = new FormState();
    $form_state->setValidationComplete();
    $this->expectException(\LogicException::class);
    $this->expectExceptionMessage('Form errors cannot be set after form validation has finished.');
    $form_state->setErrorByName('test', 'message');
  }

  /** * @covers ::prepareCallback */
  public function testPrepareCallbackValidMethod() {
    $form_state = new FormState();
    $form_state->setFormObject(new PrepareCallbackTestForm());
    
Home | Imprint | This part of the site doesn't use cookies.