isRebuilding example

$element[$key]['#access'] = FALSE;
              $display_warning = TRUE;
            }
          }
          else {
            $element[$key]['#access'] = FALSE;
          }
        }
      }
    }

    if ($display_warning && !$form_state->isSubmitted() && !$form_state->isRebuilding()) {
      $url = $entity->getUntranslated()->toUrl('edit-form')->toString();
      $this->messenger->addWarning($this->t('Fields that apply to all languages are hidden to avoid conflicting changes. <a href=":url">Edit them on the original language form</a>.', [':url' => $url]));
    }

    return $element;
  }

  /** * Adds a clue about the form element translatability. * * If the given element does not have a #title attribute, the function is * recursively applied to child elements. * * @param array $element * A form element array. */
->shouldBeCalled();

    $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setRebuild($rebuild));
  }

  /** * @covers ::isRebuilding * * @dataProvider providerSingleBooleanArgument */
  public function testIsRebuilding($rebuild) {
    $this->decoratedFormState->isRebuilding()
      ->willReturn($rebuild)
      ->shouldBeCalled();

    $this->assertSame($rebuild$this->formStateDecoratorBase->isRebuilding());
  }

  /** * @covers ::setInvalidToken * * @dataProvider providerSingleBooleanArgument */
  
/** * {@inheritdoc} */
  public function getRedirect() {
    // Skip redirection for form submissions invoked via     // \Drupal\Core\Form\FormBuilderInterface::submitForm().     if ($this->isProgrammed()) {
      return FALSE;
    }
    // Skip redirection if rebuild is activated.     if ($this->isRebuilding()) {
      return FALSE;
    }
    // Skip redirection if it was explicitly disallowed.     if ($this->isRedirectDisabled()) {
      return FALSE;
    }

    return $this->redirect;
  }

  /** * Sets the global status of errors. * * @param bool $errors * TRUE if any form has any errors, FALSE otherwise. */

  public static function processMultiple($element, FormStateInterface $form_state$form) {
    $element_children = Element::children($element, TRUE);
    $count = count($element_children);

    // Count the number of already uploaded files, in order to display new     // items in \Drupal\file\Element\ManagedFile::uploadAjaxCallback().     if (!$form_state->isRebuilding()) {
      $count_items_before = 0;
      foreach ($element_children as $children) {
        if (!empty($element[$children]['#default_value']['fids'])) {
          $count_items_before++;
        }
      }

      $form_state->set('file_upload_delta_initial', $count_items_before);
    }

    foreach ($element_children as $delta => $key) {
      
/** * {@inheritdoc} */
  public function getFormId() {
    return 'form_test_storage_form';
  }

  /** * {@inheritdoc} */
  public function buildForm(array $form, FormStateInterface $form_state) {
    if ($form_state->isRebuilding()) {
      $form_state->setUserInput([]);
    }
    // Initialize     $storage = $form_state->getStorage();
    $session = $this->getRequest()->getSession();
    if (empty($storage)) {
      $user_input = $form_state->getUserInput();
      if (empty($user_input)) {
        $session->set('constructions', 0);
      }
      // Put the initial thing into the storage
/** * {@inheritdoc} */
  public function form(array $form, FormStateInterface $form_state) {
    // Try to restore from temp store, this must be done before calling     // parent::form().     $store = $this->tempStoreFactory->get('node_preview');

    // Attempt to load from preview when the uuid is present unless we are     // rebuilding the form.     $request_uuid = \Drupal::request()->query->get('uuid');
    if (!$form_state->isRebuilding() && $request_uuid && $preview = $store->get($request_uuid)) {
      /** @var \Drupal\Core\Form\FormStateInterface $preview */

      $form_state->setStorage($preview->getStorage());
      $form_state->setUserInput($preview->getUserInput());

      // Rebuild the form.       $form_state->setRebuild();

      // The combination of having user input and rebuilding the form means       // that it will attempt to cache the form state which will fail if it is       // a GET request.
    // the currently available options attached to it, use that. However, only     // perform this check during the form rebuild. During the initial build     // after #ajax is triggered, we need to rebuild the form as it was     // initially. We need to check FormState::getUserInput() rather than     // $form_state->getValues() here because the triggering element often has     // the #limit_validation_errors property set to prevent unwanted errors     // elsewhere on the form. This means that the $form_state->getValues() array     // won't be complete. We could make it complete by adding each required part     // of the form to the #limit_validation_errors property individually as the     // form is being built, but this is difficult to do for a highly dynamic and     // extensible form. This method is much simpler.     $user_input = $form_state->isRebuilding() ? $form_state->getUserInput() : [];
    if (!empty($user_input)) {
      $key_exists = NULL;
      $submitted = NestedArray::getValue($user_input$parents$key_exists);
      // Check that the user-submitted value is one of the allowed options before       // returning it. This is not a substitute for actual form validation;       // rather it is necessary because, for example, the same select element       // might have #options A, B, and C under one set of conditions but #options       // D, E, F under a different set of conditions. So the form submission       // might have occurred with option A selected, but when the form is rebuilt       // option A is no longer one of the choices. In that case, we don't want to       // use the value that was submitted anymore but rather fall back to the
      // 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.         if ($submit_response) {
          return $submit_response;
        }
      }

      

  public function setRebuild($rebuild = TRUE) {
    $this->decoratedFormState->setRebuild($rebuild);

    return $this;
  }

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

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

    return $this;
  }

  
Home | Imprint | This part of the site doesn't use cookies.