retrieveForm example

'libraries' => '',
      ],
    ];
    $form_state = (new FormState())
      ->setRequestMethod('POST')
      ->setUserInput($input)
      ->addBuildInfo('args', [$this->editor]);

    $form_builder = $this->container->get('form_builder');
    $form_object = new EditorImageDialog(\Drupal::entityTypeManager()->getStorage('file'));
    $form_id = $form_builder->getFormId($form_object$form_state);
    $form = $form_builder->retrieveForm($form_id$form_state);
    $form_builder->prepareForm($form_id$form$form_state);
    $form_builder->processForm($form_id$form$form_state);

    // Assert these two values are present and we don't get the 'not-this'     // default back.     $this->assertFalse($form_state->getValue(['attributes', 'hasCaption'], 'not-this'));
  }

}


  /** * Tests custom string injection serialization. */
  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);
  }

}


  /** * Tests queue injection serialization. */
  public function testQueueSerialization() {
    $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);
    $form_builder->processForm($form_id$form$form_state);
  }

}

  protected function setupForm(FormStateInterface $form_state, FormBuilderInterface $form_builder) {
    $form_id = $form_builder->getFormId($this$form_state);
    $form = $form_builder->retrieveForm($form_id$form_state);
    $form_state->setValidationEnforced();
    $form_state->clearErrors();
    $form_builder->prepareForm($form_id$form$form_state);
    $form_builder->processForm($form_id$form$form_state);
    return $form_builder->retrieveForm($form_id$form_state);
  }

  /** * {@inheritdoc} */
  public function getFormId() {
    
/** * Tests db log injection serialization. */
  public function testLoggerSerialization() {
    $form_state = new FormState();

    // Forms are only serialized during POST requests.     $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);
    $form_builder->processForm($form_id$form$form_state);
  }

}
// If the previous bit of code didn't result in a populated $form object, we     // are hitting the form for the first time and we need to build it from     // scratch.     if (!isset($form)) {
      // If we attempted to serve the form from cache, uncacheable $form_state       // keys need to be removed after retrieving and preparing the form, except       // any that were already set prior to retrieving the form.       if ($check_cache) {
        $form_state_before_retrieval = clone $form_state;
      }

      $form = $this->retrieveForm($form_id$form_state);
      $this->prepareForm($form_id$form$form_state);

      // self::setCache() removes uncacheable $form_state keys (see properties       // in \Drupal\Core\Form\FormState) in order for multi-step forms to work       // properly. This means that form processing logic for single-step forms       // using $form_state->isCached() may depend on data stored in those keys       // during self::retrieveForm()/self::prepareForm(), but form processing       // should not depend on whether the form is cached or not, so $form_state       // is adjusted to match what it would be after a       // self::setCache()/self::getCache() sequence. These exceptions are       // allowed to survive here:
Home | Imprint | This part of the site doesn't use cookies.