disableRedirect example

->shouldBeCalled();

    $this->assertSame($must_validate$this->formStateDecoratorBase->isValidationEnforced());
  }

  /** * @covers ::disableRedirect * * @dataProvider providerSingleBooleanArgument */
  public function testDisableRedirect($no_redirect) {
    $this->decoratedFormState->disableRedirect($no_redirect)
      ->shouldBeCalled();

    $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->disableRedirect($no_redirect));
  }

  /** * @covers ::isRedirectDisabled * * @dataProvider providerSingleBooleanArgument */
  public function testIsRedirectDisabled($no_redirect) {
    
public function getFormState(ViewEntityInterface $view$display_id$js) {
    // $js may already have been converted to a Boolean.     $ajax = is_string($js) ? $js === 'ajax' : $js;
    return (new FormState())
      ->set('form_id', $this->getFormId())
      ->set('form_key', $this->getFormKey())
      ->set('ajax', $ajax)
      ->set('display_id', $display_id)
      ->set('view', $view)
      ->set('type', $this->type)
      ->set('id', $this->id)
      ->disableRedirect()
      ->addBuildInfo('callback_object', $this);
  }

  /** * {@inheritdoc} */
  public function getForm(ViewEntityInterface $view$display_id$js) {
    /** @var \Drupal\Core\Form\FormStateInterface $form_state */
    $form_state = $this->getFormState($view$display_id$js);
    $view = $form_state->get('view');
    $form_key = $form_state->get('form_key');

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

  /** * {@inheritdoc} */
  public function disableRedirect($no_redirect = TRUE) {
    $this->decoratedFormState->disableRedirect($no_redirect);

    return $this;
  }

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

  

  public function testGetPostAjaxRequest() {
    $request = new Request([FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]['form_id' => 'different_form_id']);
    $request->setMethod('POST');
    $this->requestStack->push($request);

    $form_state = (new FormState())
      ->setUserInput([FormBuilderInterface::AJAX_FORM_REQUEST => TRUE])
      ->setMethod('get')
      ->setAlwaysProcess()
      ->disableRedirect()
      ->set('ajax', TRUE);

    $form_id = '\Drupal\Tests\Core\Form\TestForm';
    $expected_form = (new TestForm())->buildForm([]$form_state);

    $form = $this->formBuilder->buildForm($form_id$form_state);
    $this->assertFormElement($expected_form$form, 'test');
    $this->assertSame('test-form', $form['#id']);
  }

  /** * @covers ::buildForm * * @dataProvider providerTestChildAccessInheritance */
      if ($check_cache) {
        $cache_form_state = $form_state->getCacheableArray();
        $cache_form_state['always_process'] = $form_state->getAlwaysProcess();
        $cache_form_state['temporary'] = $form_state->getTemporary();
        $form_state = $form_state_before_retrieval;
        $form_state->setFormState($cache_form_state);
      }
    }

    // If this form is an AJAX request, disable all form redirects.     if ($ajax_form_request = $request->query->has(static::AJAX_FORM_REQUEST)) {
      $form_state->disableRedirect();
    }

    // Now that we have a constructed form, process it. This is where:     // - Element #process functions get called to further refine $form.     // - User input, if any, gets incorporated in the #value property of the     // corresponding elements and into $form_state->getValues().     // - Validation and submission handlers are called.     // - If this submission is part of a multistep workflow, the form is rebuilt     // to contain the information of the next step.     // - If necessary, the form and form state are cached or re-cached, so that     // appropriate information persists to the next page request.

  public function submitForm(array &$form, FormStateInterface $form_state) {
    if (!$form_state->isValueEmpty('redirection')) {
      if (!$form_state->isValueEmpty('destination')) {
        // The destination is a random URL, so we can't use routed URLs.         // @todo Revisit this in https://www.drupal.org/node/2418219.         $form_state->setRedirectUrl(Url::fromUserInput('/' . $form_state->getValue('destination')));
      }
    }
    else {
      $form_state->disableRedirect();
    }
  }

}

  public function renderExposedForm($block = FALSE) {
    // Deal with any exposed filters we may have, before building.     $form_state = (new FormState())
      ->setStorage([
        'view' => $this->view,
        'display' => &$this->view->display_handler->display,
        'rerender' => TRUE,
      ])
      ->setMethod('get')
      ->setAlwaysProcess()
      ->disableRedirect();

    // Some types of displays (eg. attachments) may wish to use the exposed     // filters of their parent displays instead of showing an additional     // exposed filter form for the attachment as well as that for the parent.     if (!$this->view->display_handler->displaysExposed() || (!$block && $this->view->display_handler->getOption('exposed_block'))) {
      $form_state->set('rerender', NULL);
    }

    if (!empty($this->ajax)) {
      $form_state->set('ajax', TRUE);
    }

    
$form['op'] = ['#type' => 'submit', '#value' => 'Submit'];
    // The form token CSRF protection should not interfere with this test, so we     // bypass it by setting the token to FALSE.     $form['#token'] = FALSE;

    $edit['form_id'] = $form_id;

    // Disable page redirect for forms submitted programmatically. This is a     // solution to skip the redirect step (there are no pages, then the redirect     // isn't possible).     $form_state->disableRedirect();
    $form_state->setUserInput($edit);
    $form_state->setFormObject(new StubForm($form_id$form));

    \Drupal::formBuilder()->prepareForm($form_id$form$form_state);

    \Drupal::formBuilder()->processForm($form_id$form$form_state);

    $errors = $form_state->getErrors();

    // Clear errors and messages.     \Drupal::messenger()->deleteAll();
    
$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 */
  
return $form;
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    if ($form_state->get('json')) {
      $form_state->setResponse(new JsonResponse($form_state->getValues()));
    }
    else {
      $form_state->disableRedirect();
    }
  }

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