本文整理汇总了PHP中Drupal\Core\Form\FormStateInterface::getRedirect方法的典型用法代码示例。如果您正苦于以下问题:PHP FormStateInterface::getRedirect方法的具体用法?PHP FormStateInterface::getRedirect怎么用?PHP FormStateInterface::getRedirect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Form\FormStateInterface
的用法示例。
在下文中一共展示了FormStateInterface::getRedirect方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
if (!$form_state->getRedirect()) {
$data = \Drupal::moduleHandler()->invokeAll('uc_add_to_cart_data', array($form_state->getValues()));
$msg = $this->config('uc_cart.settings')->get('add_item_msg');
$cart = Cart::create(\Drupal::getContainer());
$redirect = $cart->addItem($form_state->getValue('nid'), $form_state->getValue('qty'), $data, NULL, $msg);
if (isset($redirect)) {
$form_state->setRedirectUrl($redirect);
}
}
}
示例2: submitDelayDestination
/**
* Submit handler for form buttons that do not complete a form workflow.
*
* The Edit View form is a multistep form workflow, but with state managed by
* the SharedTempStore rather than $form_state->setRebuild(). Without this
* submit handler, buttons that add or remove displays would redirect to the
* destination parameter (e.g., when the Edit View form is linked to from a
* contextual link). This handler can be added to buttons whose form submission
* should not yet redirect to the destination.
*/
public function submitDelayDestination($form, FormStateInterface $form_state)
{
$request = $this->requestStack->getCurrentRequest();
$destination = $request->query->get('destination');
$redirect = $form_state->getRedirect();
// If there is a destination, and redirects are not explicitly disabled, add
// the destination as a query string to the redirect and suppress it for the
// current request.
if (isset($destination) && $redirect !== FALSE) {
// Create a valid redirect if one does not exist already.
if (!$redirect instanceof Url) {
$redirect = Url::createFromRequest($request);
}
// Add the current destination to the redirect unless one exists already.
$options = $redirect->getOptions();
if (!isset($options['query']['destination'])) {
$options['query']['destination'] = $destination;
$redirect->setOptions($options);
}
$form_state->setRedirectUrl($redirect);
$request->query->remove('destination');
}
}
示例3: getRedirect
/**
* {@inheritdoc}
*/
public function getRedirect()
{
return $this->mainFormState->getRedirect();
}
示例4: redirectForm
/**
* {@inheritdoc}
*/
public function redirectForm(FormStateInterface $form_state)
{
$redirect = $form_state->getRedirect();
// Allow using redirect responses directly if needed.
if ($redirect instanceof RedirectResponse) {
return $redirect;
}
$url = NULL;
// Check for a route-based redirection.
if ($redirect instanceof Url) {
$url = $redirect->setAbsolute()->toString();
} elseif ($redirect === NULL) {
$request = $this->requestStack->getCurrentRequest();
$url = $this->urlGenerator->generateFromRoute('<current>', [], ['query' => $request->query->all(), 'absolute' => TRUE]);
}
if ($url) {
// According to RFC 7231, 303 See Other status code must be used to redirect
// user agent (and not default 302 Found).
// @see http://tools.ietf.org/html/rfc7231#section-6.4.4
return new RedirectResponse($url, Response::HTTP_SEE_OTHER);
}
}
示例5: redirectForm
/**
* {@inheritdoc}
*/
public function redirectForm(FormStateInterface $form_state)
{
$redirect = $form_state->getRedirect();
// Allow using redirect responses directly if needed.
if ($redirect instanceof RedirectResponse) {
return $redirect;
}
$url = NULL;
// Check for a route-based redirection.
if ($redirect instanceof Url) {
$url = $redirect->setAbsolute()->toString();
} elseif ($redirect === NULL) {
$request = $this->requestStack->getCurrentRequest();
// @todo Remove dependency on the internal _system_path attribute:
// https://www.drupal.org/node/2293521.
$url = $this->urlGenerator->generateFromPath($request->attributes->get('_system_path'), array('query' => $request->query->all(), 'absolute' => TRUE));
}
if ($url) {
// According to RFC 7231, 303 See Other status code must be used to redirect
// user agent (and not default 302 Found).
// @see http://tools.ietf.org/html/rfc7231#section-6.4.4
return new RedirectResponse($url, Response::HTTP_SEE_OTHER);
}
}
示例6: getRedirect
/**
* {@inheritdoc}
*/
public function getRedirect()
{
return $this->decoratedFormState->getRedirect();
}
示例7: testGetRedirect
/**
* @covers ::getRedirect
*
* @dataProvider providerGetRedirect
*
* @param bool $expected
*/
public function testGetRedirect($expected)
{
$this->decoratedFormState->getRedirect()->willReturn($expected)->shouldBeCalled();
$this->assertSame($expected, $this->formStateDecoratorBase->getRedirect());
}
示例8: redirectForm
/**
* {@inheritdoc}
*/
public function redirectForm(FormStateInterface $form_state)
{
// According to RFC 7231, 303 See Other status code must be used to redirect
// user agent (and not default 302 Found).
// @see http://tools.ietf.org/html/rfc7231#section-6.4.4
$status_code = Response::HTTP_SEE_OTHER;
$redirect = $form_state->getRedirect();
// Allow using redirect responses directly if needed.
if ($redirect instanceof RedirectResponse) {
return $redirect;
}
$url = NULL;
// Check for a route-based redirection.
if ($redirect instanceof Url) {
$url = $redirect->toString();
} elseif (is_array($redirect)) {
if (isset($redirect[1])) {
$options = $redirect[1];
} else {
$options = array();
}
// Redirections should always use absolute URLs.
$options['absolute'] = TRUE;
if (isset($redirect[2])) {
$status_code = $redirect[2];
}
$url = $this->urlGenerator->generateFromPath($redirect[0], $options);
} elseif (is_string($redirect)) {
// This function can be called from the installer, which guarantees
// that $redirect will always be a string, so catch that case here
// and use the appropriate redirect function.
if ($this->drupalInstallationAttempted()) {
install_goto($redirect);
} else {
$url = $this->urlGenerator->generateFromPath($redirect, array('absolute' => TRUE));
}
} elseif ($redirect === NULL) {
$request = $this->requestStack->getCurrentRequest();
// @todo Remove dependency on the internal _system_path attribute:
// https://www.drupal.org/node/2293521.
$url = $this->urlGenerator->generateFromPath($request->attributes->get('_system_path'), array('query' => $request->query->all(), 'absolute' => TRUE));
}
if ($url) {
return new RedirectResponse($url, $status_code);
}
}