当前位置: 首页>>代码示例>>PHP>>正文


PHP FormStateInterface::getRedirect方法代码示例

本文整理汇总了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);
         }
     }
 }
开发者ID:pedrocones,项目名称:hydrotools,代码行数:15,代码来源:BuyItNowForm.php

示例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');
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:33,代码来源:ViewEditForm.php

示例3: getRedirect

 /**
  * {@inheritdoc}
  */
 public function getRedirect()
 {
     return $this->mainFormState->getRedirect();
 }
开发者ID:Laudanum,项目名称:authorization,代码行数:7,代码来源:SubFormState.php

示例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);
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:25,代码来源:FormSubmitter.php

示例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);
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:27,代码来源:FormSubmitter.php

示例6: getRedirect

 /**
  * {@inheritdoc}
  */
 public function getRedirect()
 {
     return $this->decoratedFormState->getRedirect();
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:7,代码来源:FormStateDecoratorBase.php

示例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());
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:12,代码来源:FormStateDecoratorBaseTest.php

示例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);
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:49,代码来源:FormSubmitter.php


注:本文中的Drupal\Core\Form\FormStateInterface::getRedirect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。