setTriggeringElement example

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

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

    return $this;
  }

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

  
/** * @covers ::buildResponse */
  public function testBuildResponseNoCallable() {
    $this->renderer->expects($this->never())
      ->method('renderResponse');

    $request = new Request();
    $form = [];
    $form_state = new FormState();
    $triggering_element = [];
    $form_state->setTriggeringElement($triggering_element);
    $commands = [];

    $this->expectException(HttpException::class);
    $this->formAjaxResponseBuilder->buildResponse($request$form$form_state$commands);
  }

  /** * @covers ::buildResponse */
  public function testBuildResponseRenderArray() {
    $triggering_element = [
      

  public function testHandleErrorsWithLimitedValidation($sections$triggering_element$values$expected) {
    $form_validator = new FormValidator(new RequestStack()$this->getStringTranslationStub()$this->csrfToken, $this->logger, $this->formErrorHandler);

    $triggering_element['#limit_validation_errors'] = $sections;
    $form = [];
    $form_state = (new FormState())
      ->setValues($values)
      ->setTriggeringElement($triggering_element);

    $form_validator->validateForm('test_form_id', $form$form_state);
    $this->assertSame($expected$form_state->getValues());
  }

  public function providerTestHandleErrorsWithLimitedValidation() {
    return [
      // Test with a non-existent section.       [
        [['test1']['test3']],
        [],
        [

  }

  /** * @covers ::setTriggeringElement */
  public function testSetTriggeringElement() {
    $triggering_element = [
      'FOO' => 'BAR',
    ];

    $this->decoratedFormState->setTriggeringElement($triggering_element)
      ->shouldBeCalled();

    $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setTriggeringElement($triggering_element));
  }

  /** * @covers ::getTriggeringElement */
  public function testGetTriggeringElement() {
    $triggering_element = [
      'FOO' => 'BAR',
    ];
// Only process the input if we have a correct form submission.     if ($form_state->isProcessingInput()) {
      // Form values for programmed form submissions typically do not include a       // value for the submit button. But without a triggering element, a       // potentially existing #limit_validation_errors property on the primary       // submit button is not taken account. Therefore, check whether there is       // exactly one submit button in the form, and if so, automatically use it       // as triggering_element.       $buttons = $form_state->getButtons();
      if ($form_state->isProgrammed() && !$form_state->getTriggeringElement() && count($buttons) == 1) {
        $form_state->setTriggeringElement(reset($buttons));
      }
      $this->formValidator->validateForm($form_id$form$form_state);

      // If there are no errors and the form is not rebuilding, submit the form.       if (!$form_state->isRebuilding() && !FormState::hasAnyErrors()) {
        $submit_response = $this->formSubmitter->doSubmitForm($form$form_state);
        // If this form was cached, delete it from the cache after submission.         if ($form_state->isCached()) {
          $this->deleteCache($form['#build_id']);
        }
        // If the form submission directly returned a response, return it now.
Home | Imprint | This part of the site doesn't use cookies.