Example #1
0
 /**
  * Builds the cancel link for a confirmation form.
  *
  * @param \Drupal\Core\Form\ConfirmFormInterface $form
  *   The confirmation form.
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request.
  *
  * @return array
  *   The link render array for the cancel form.
  */
 public static function buildCancelLink(ConfirmFormInterface $form, Request $request)
 {
     // Prepare cancel link.
     $query = $request->query;
     // If a destination is specified, that serves as the cancel link.
     if ($query->has('destination')) {
         $options = UrlHelper::parse($query->get('destination'));
         // @todo Revisit this in https://www.drupal.org/node/2418219.
         $url = Url::fromUserInput('/' . $options['path'], $options);
     } else {
         $url = $form->getCancelUrl();
     }
     return ['#type' => 'link', '#title' => $form->getCancelText(), '#attributes' => ['class' => ['button']], '#url' => $url];
 }
 /**
  * Builds the cancel link for a confirmation form.
  *
  * @param \Drupal\Core\Form\ConfirmFormInterface $form
  *   The confirmation form.
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request.
  *
  * @return array
  *   The link render array for the cancel form.
  */
 public static function buildCancelLink(ConfirmFormInterface $form, Request $request)
 {
     // Prepare cancel link.
     $query = $request->query;
     // If a destination is specified, that serves as the cancel link.
     if ($query->has('destination')) {
         $options = UrlHelper::parse($query->get('destination'));
         // @todo Use Url::fromPath() once https://www.drupal.org/node/2351379 is
         //   resolved.
         $url = Url::fromUri('base://' . $options['path'], $options);
     } else {
         $url = $form->getCancelUrl();
     }
     return ['#type' => 'link', '#title' => $form->getCancelText(), '#url' => $url];
 }
Example #3
0
 /**
  * Builds the cancel link for a confirmation form.
  *
  * @param \Drupal\Core\Form\ConfirmFormInterface $form
  *   The confirmation form.
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request.
  *
  * @return array
  *   The link render array for the cancel form.
  */
 public static function buildCancelLink(ConfirmFormInterface $form, Request $request)
 {
     // Prepare cancel link.
     $query = $request->query;
     // If a destination is specified, that serves as the cancel link.
     if ($query->has('destination')) {
         $options = UrlHelper::parse($query->get('destination'));
         $link = array('#href' => $options['path'], '#options' => $options);
     } elseif ($route = $form->getCancelRoute()) {
         $link = $route->toRenderArray();
     }
     $link['#type'] = 'link';
     $link['#title'] = $form->getCancelText();
     return $link;
 }
Example #4
0
 /**
  * Builds the cancel link for a confirmation form.
  *
  * @param \Drupal\Core\Form\ConfirmFormInterface $form
  *   The confirmation form.
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request.
  *
  * @return array
  *   The link render array for the cancel form.
  */
 public static function buildCancelLink(ConfirmFormInterface $form, Request $request)
 {
     // Prepare cancel link.
     $query = $request->query;
     $url = NULL;
     // If a destination is specified, that serves as the cancel link.
     if ($query->has('destination')) {
         $options = UrlHelper::parse($query->get('destination'));
         // @todo Revisit this in https://www.drupal.org/node/2418219.
         try {
             $url = Url::fromUserInput('/' . ltrim($options['path'], '/'), $options);
         } catch (\InvalidArgumentException $e) {
             // Suppress the exception and fall back to the form's cancel url.
         }
     }
     // Check for a route-based cancel link.
     if (!$url) {
         $url = $form->getCancelUrl();
     }
     return ['#type' => 'link', '#title' => $form->getCancelText(), '#attributes' => ['class' => ['button']], '#url' => $url];
 }