setSubmitted example

// Populate FormState::$input with the submitted values before retrieving     // the form, to be consistent with what self::buildForm() does for     // non-programmatic submissions (form builder functions may expect it to be     // 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} */
$this->decoratedFormState->getSubmitHandlers()
      ->willReturn($submit_handlers)
      ->shouldBeCalled();

    $this->assertSame($submit_handlers$this->formStateDecoratorBase->getSubmitHandlers());
  }

  /** * @covers ::setSubmitted */
  public function testSetSubmitted() {
    $this->decoratedFormState->setSubmitted()
      ->shouldBeCalled();

    $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setSubmitted());
  }

  /** * @covers ::isSubmitted * * @dataProvider providerSingleBooleanArgument * * @param bool $submitted * Any valid value for * \Drupal\Core\Form\FormStateInterface::isSubmitted()'s return * value. */
public function testDatetimeSerialization() {
    $form_state = new FormState();
    $form_state->setRequestMethod('POST');
    $form_state->setCached();
    $form_builder = $this->container->get('form_builder');
    $form_id = $form_builder->getFormId($this$form_state);
    $form = $form_builder->retrieveForm($form_id$form_state);
    $form_builder->prepareForm($form_id$form$form_state);
    // Set up $form_state so that the form is properly submitted.     $form_state->setUserInput(['form_id' => $form_id]);
    $form_state->setProgrammed();
    $form_state->setSubmitted();
    $form_builder->processForm($form_id$form$form_state);
  }

}
$form_object->setEntity($entity->reveal());

    $form = [
      '#fields' => array_keys($field_values),
      '#extra' => [],
    ];
    $form_state = new FormState();
    $form_state->setValues(['fields' => $field_values]);
    $form_state->setProcessInput();

    $form_object->buildEntity($form$form_state);
    $form_state->setSubmitted();

    // Flag one field for updating plugin settings.     $form_state->set('plugin_settings_update', 'field_plugin_settings_update');
    // During form submission, buildEntity() will be called twice. Simulate that     // here to prove copyFormValuesToEntity() is idempotent.     $form_object->buildEntity($form$form_state);
  }

}

    $entity->save();

    $form_object = $this->entityTypeManager->getFormObject($this->entityTypeId, 'default');
    $form_object->setEntity($entity);

    $form_state = new FormState();
    $form_state
      ->addBuildInfo('callback_object', $form_object)
      ->set(['content_translation', 'translation_form']$translation_form);
    if ($is_submitted) {
      $form_state->setSubmitted();
    }
    $form_state->setRebuild($is_rebuilding);

    $handler = $this->entityTypeManager->getHandler($this->entityTypeId, 'translation');
    $actual = $handler->entityFormSharedElements($element$form_state$element);

    $this->assertEquals($expected$actual);
    if ($display_warning) {
      $messages = $this->messenger->messagesByType('warning');
      $this->assertCount(1, $messages);
      $expected_message = sprintf('Fields that apply to all languages are hidden to avoid conflicting changes. <a href="%s">Edit them on the original language form</a>.', $entity->toUrl('edit-form')->toString());
      
$this->assertFalse($form_state->isExecuted());
    $this->assertNull($return);
  }

  /** * @covers ::doSubmitForm */
  public function testHandleFormSubmissionNoRedirect() {
    $form_submitter = $this->getFormSubmitter();
    $form = [];
    $form_state = (new FormState())
      ->setSubmitted()
      ->disableRedirect();

    $return = $form_submitter->doSubmitForm($form$form_state);
    $this->assertTrue($form_state->isExecuted());
    $this->assertNull($return);
  }

  /** * @covers ::doSubmitForm * * @dataProvider providerTestHandleFormSubmissionWithResponses */
/** * {@inheritdoc} */
  public function getSubmitHandlers() {
    return $this->decoratedFormState->getSubmitHandlers();
  }

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

    return $this;
  }

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

  

  protected function simulateFormSubmission($form_id, FormInterface $form_arg, FormStateInterface $form_state$programmed = TRUE) {
    $input = $form_state->getUserInput();
    $input['op'] = 'Submit';
    $form_state
      ->setUserInput($input)
      ->setProgrammed($programmed)
      ->setSubmitted();
    return $this->formBuilder->buildForm($form_arg$form_state);
  }

  /** * Asserts that the expected form structure is found in a form for a given key. * * @param array $expected_form * The expected form structure. * @param array $actual_form * The actual form. * @param string|null $form_key * (optional) The form key to look in. Otherwise the entire form will be * compared. */
Home | Imprint | This part of the site doesn't use cookies.