setValidateHandlers example

->with($this->isType('array')$this->isInstanceOf('Drupal\Core\Form\FormStateInterface'));

    $form = [];
    $form_state = new FormState();
    $form_validator->executeValidateHandlers($form$form_state);

    $form['#validate'][] = [$mock, 'hash_validate'];
    $form_validator->executeValidateHandlers($form$form_state);

    // $form_state validate handlers will supersede $form handlers.     $validate_handlers[] = [$mock, 'validate_handler'];
    $form_state->setValidateHandlers($validate_handlers);
    $form_validator->executeValidateHandlers($form$form_state);
  }

  /** * @covers ::doValidateForm * * @dataProvider providerTestRequiredErrorMessage */
  public function testRequiredErrorMessage($element$expected_message) {
    $form_validator = $this->getMockBuilder('Drupal\Core\Form\FormValidator')
      ->setConstructorArgs([new RequestStack()$this->getStringTranslationStub()$this->csrfToken, $this->logger, $this->formErrorHandler])
      
      // been identified yet, default it to the first button.       $buttons = $form_state->getButtons();
      if (!$form_state->isProgrammed() && !$form_state->getTriggeringElement() && !empty($buttons)) {
        $form_state->setTriggeringElement($buttons[0]);
      }

      $triggering_element = $form_state->getTriggeringElement();
      // If the triggering element specifies "button-level" validation and       // submit handlers to run instead of the default form-level ones, then add       // those to the form state.       if (isset($triggering_element['#validate'])) {
        $form_state->setValidateHandlers($triggering_element['#validate']);
      }
      if (isset($triggering_element['#submit'])) {
        $form_state->setSubmitHandlers($triggering_element['#submit']);
      }

      // If the triggering element executes submit handlers, then set the form       // state key that's needed for those handlers to run.       if (!empty($triggering_element['#executes_submit_callback'])) {
        $form_state->setSubmitted();
      }

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

  /** * {@inheritdoc} */
  public function setValidateHandlers(array $validate_handlers) {
    $this->decoratedFormState->setValidateHandlers($validate_handlers);

    return $this;
  }

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

  
$this->assertSame($triggering_element$this->formStateDecoratorBase->getTriggeringElement());
  }

  /** * @covers ::setValidateHandlers */
  public function testSetValidateHandlers() {
    $validate_handlers = [
      'FOO' => 'BAR',
    ];

    $this->decoratedFormState->setValidateHandlers($validate_handlers)
      ->shouldBeCalled();

    $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setValidateHandlers($validate_handlers));
  }

  /** * @covers ::getValidateHandlers */
  public function testGetValidateHandlers() {
    $validate_handlers = [
      'FOO' => 'BAR',
    ];
Home | Imprint | This part of the site doesn't use cookies.