setRebuild example

    if ($this->getRequest()->get('cache') && $form_state->getValue('value') == 'change_title') {
      $form_state->set(['thing', 'changed'], TRUE);
    }
  }

  /** * {@inheritdoc} */
  public function continueSubmitForm(array &$form, FormStateInterface $form_state) {
    $form_state->set(['thing', 'title']$form_state->getValue('title'));
    $form_state->set(['thing', 'value']$form_state->getValue('value'));
    $form_state->setRebuild();
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->messenger()->addStatus("Title: " . Html::escape($form_state->getValue('title')));
    $this->messenger()->addStatus("Form constructions: " . $this->getRequest()->getSession()->get('constructions'));
    if ($form_state->has(['thing', 'changed'])) {
      $this->messenger()->addStatus("The thing has been changed.");
    }
    
/** * @covers ::setRebuild * * @dataProvider providerSingleBooleanArgument * * @param bool $rebuild * Any valid value for \Drupal\Core\Form\FormStateInterface::setRebuild()'s * $rebuild argument. */
  public function testSetRebuild($rebuild) {
    $this->decoratedFormState->setRebuild($rebuild)
      ->shouldBeCalled();

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

  /** * @covers ::isRebuilding * * @dataProvider providerSingleBooleanArgument */
  public function testIsRebuilding($rebuild) {
    


  /** * {@inheritdoc} */
  public function validateForm(array &$form, FormStateInterface $form_state) {}

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $form_state->setRebuild();
  }

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->installSchema('system', ['sequences']);
    $this->installEntitySchema('user');
    // We only need a valid \Drupal\Core\Queue\DatabaseQueue object here, not     // an actual valid queue.
// 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.       $form_state->setRequestMethod('POST');

      $this->entity = $preview->getFormObject()->getEntity();
      $this->entity->in_preview = NULL;

      $form_state->set('has_been_previewed', TRUE);
    }

    
'#type' => 'submit',
      '#value' => t('Submit'),
    ];
    return $form;
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->messenger()->addStatus($form_state->get('value'));
    $form_state->setRebuild();
  }

}
$views_session = $session->get('views', []);
    if (isset($views_session[$this->view->storage->id()][$display_id])) {
      unset($views_session[$this->view->storage->id()][$display_id]);
    }
    $session->set('views', $views_session);

    // Set the form to allow redirect.     if (empty($this->view->live_preview) && !\Drupal::request()->isXmlHttpRequest()) {
      $form_state->disableRedirect(FALSE);
    }
    else {
      $form_state->setRebuild();
      $this->view->exposed_data = [];
    }

    $form_state->setRedirect('<current>');
    $form_state->setValues([]);
  }

  /** * {@inheritdoc} */
  public function getCacheMaxAge() {
    

  public static function settingsAjax($form, FormStateInterface $form_state) {
    return NestedArray::getValue($form$form_state->getTriggeringElement()['#ajax']['element']);
  }

  /** * Submit handler for the non-JS case. * * @see static::fieldSettingsForm() */
  public static function settingsAjaxSubmit($form, FormStateInterface $form_state) {
    $form_state->setRebuild();
  }

  /** * {@inheritdoc} */
  public static function getPreconfiguredOptions() {
    $options = [];

    // Add all the commonly referenced entity types as distinct pre-configured     // options.     $entity_types = \Drupal::entityTypeManager()->getDefinitions();
    
/** * Ajax callback for the size selection element. */
  public static function updateSize(array $form, FormStateInterface $form_state) {
    return $form['size_wrapper'];
  }

  /** * Element submit handler for non-JS testing. */
  public static function changeSize(array $form, FormStateInterface $form_state) {
    $form_state->setRebuild();
  }

  /** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    $entity = $this->entity;
    $status = $entity->save();

    if ($status === SAVED_UPDATED) {
      $this->messenger()->addStatus(new FormattableMarkup('%label configuration has been updated.', ['%label' => $entity->label()]));
    }

        );
      }
      else {
        $form_state->setRedirectUrl($block->toUrl('collection'));
      }
    }
    else {
      // In the unlikely case something went wrong on save, the block will be       // rebuilt and block form redisplayed.       $this->messenger()->addError($this->t('The block could not be saved.'));
      $form_state->setRebuild();
    }
  }

}
/** * Validate callback that forces a form rebuild. */
  public function buildAjaxSnackConfigureFormValidate(array $form, FormStateInterface $form_state) {
    $form_state->set('id', $form_state->getValue('id'));
  }

  /** * Submit callback that forces a form rebuild. */
  public function buildAjaxSnackConfigureFormSubmit(array $form, FormStateInterface $form_state) {
    $form_state->setRebuild();
  }

  /** * Handles changes to the selected snack configuration. */
  public function buildAjaxSnackConfigureForm(array $form, FormStateInterface $form_state) {
    return $form['snack_configs'];
  }

  /** * Loading stub for machine name. * * @param $machine_name * The machine name. * * @return bool */
/** * {@inheritdoc} */
  public function validateForm(array &$form, FormStateInterface $form_state) {}

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->assertTrue(TRUE);
    $form_state->setRebuild();
  }

  /** * 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);
    
      // sense to redisplay the identical form without an error for the user to       // correct, so we also rebuild error-free non-executed forms, regardless       // of $form_state->isRebuilding().       // @todo Simplify this logic; considering Ajax and non-HTML front-ends,       // along with element-level #submit properties, it makes no sense to       // have divergent form execution based on whether the triggering element       // has #executes_submit_callback set to TRUE.       if (($form_state->isRebuilding() || !$form_state->isExecuted()) && !FormState::hasAnyErrors()) {
        // Form building functions (e.g., self::handleInputElement()) may use         // $form_state->isRebuilding() to determine if they are running in the         // context of a rebuild, so ensure it is set.         $form_state->setRebuild();
        $form = $this->rebuildForm($form_id$form_state$form);
      }
    }

    // After processing the form, the form builder or a #process callback may     // have called $form_state->setCached() to indicate that the form and form     // state shall be cached. But the form may only be cached if     // $form_state->disableCache() is not called. Only cache $form as it was     // prior to self::doBuildForm(), because self::doBuildForm() must run for     // each request to accommodate new user input. Rebuilt forms are not cached     // here, because self::rebuildForm() already takes care of that.
$view = $form_state->get('view');
    $display_id = $form_state->get('display_id');
    $type = $form_state->get('type');
    $id = $form_state->get('id');
    $view->getExecutable()->setHandler($display_id$type$id$item);

    $view->addFormToStack($form_state->get('form_key')$display_id$type$id, TRUE, TRUE);

    $view->cacheSet();
    $form_state->set('rerender', TRUE);
    $form_state->setRebuild();
    $form_state->set('force_expose_options', TRUE);
  }

  /** * Submits a temporary form. * * A submit handler that is used for storing temporary items when using * multi-step changes, such as ajax requests. */
  public function submitTemporaryForm($form, FormStateInterface $form_state) {
    // Run it through the handler's submit function.
'#value' => 'Submit',
    ];
    return $form;
  }

  /** * {@inheritdoc} */
  public function addMoreSubmitForm(array &$form, FormStateInterface $form_state) {
    // Rebuild, to test preservation of input values.     $form_state->set('add_more', TRUE);
    $form_state->setRebuild();
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    // Finish the workflow. Do not rebuild.     $this->messenger()->addStatus($this->t('Form values: %values', ['%values' => var_export($form_state->getValues(), TRUE)]));
  }

}
$form_state->setResponse($response);
          }
        }
        catch (\Exception $e) {
          // If there is no database available, we don't care and just skip           // this part entirely.         }

        break;

      case 'enter_connection_settings':
        $form_state->setRebuild();
        break;

      case 'change_connection_type':
        $form_state->setRebuild();
        $form_state->unsetValue(['connection_settings', 'authorize_filetransfer_default']);
        break;
    }
  }

  /** * Gets a FileTransfer class for a specific transfer method and settings. * * @param $backend * The FileTransfer backend to get the class for. * @param $settings * Array of settings for the FileTransfer. * * @return \Drupal\Core\FileTransfer\FileTransfer|bool * An instantiated FileTransfer object for the requested method and settings, * or FALSE if there was an error finding or instantiating it. */
Home | Imprint | This part of the site doesn't use cookies.