executeValidateHandlers example

if ($is_empty_multiple || $is_empty_string || $is_empty_value || $is_empty_null) {
          // Flag this element as #required_but_empty to allow #element_validate           // handlers to set a custom required error message, but without having           // to re-implement the complex logic to figure out whether the field           // value is empty.           $elements['#required_but_empty'] = TRUE;
        }
      }

      // Call user-defined form level validators.       if (isset($form_id)) {
        $this->executeValidateHandlers($elements$form_state);
      }
      // Call any element-specific validators. These must act on the element       // #value data.       elseif (isset($elements['#element_validate'])) {
        foreach ($elements['#element_validate'] as $callback) {
          $complete_form = &$form_state->getCompleteForm();
          call_user_func_array($form_state->prepareCallback($callback)[&$elements, &$form_state, &$complete_form]);
        }
      }

      // Ensure that a #required form error is thrown, regardless of whether
/** * {@inheritdoc} */
  public function redirectForm(FormStateInterface $form_state) {
    return $this->formSubmitter->redirectForm($form_state);
  }

  /** * {@inheritdoc} */
  public function executeValidateHandlers(&$form, FormStateInterface &$form_state) {
    $this->formValidator->executeValidateHandlers($form$form_state);
  }

  /** * {@inheritdoc} */
  public function executeSubmitHandlers(&$form, FormStateInterface &$form_state) {
    $this->formSubmitter->executeSubmitHandlers($form$form_state);
  }

  /** * {@inheritdoc} */
->onlyMethods(['validate_handler', 'hash_validate', 'element_validate'])
      ->getMock();
    $mock->expects($this->once())
      ->method('validate_handler')
      ->with($this->isType('array')$this->isInstanceOf('Drupal\Core\Form\FormStateInterface'));
    $mock->expects($this->once())
      ->method('hash_validate')
      ->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 */
Home | Imprint | This part of the site doesn't use cookies.