diff --git a/core/lib/Drupal/Core/Entity/EntityConfirmFormBase.php b/core/lib/Drupal/Core/Entity/EntityConfirmFormBase.php index 565514d..28b80d4 100644 --- a/core/lib/Drupal/Core/Entity/EntityConfirmFormBase.php +++ b/core/lib/Drupal/Core/Entity/EntityConfirmFormBase.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Entity; -use Drupal\Component\Utility\Url; +use Drupal\Core\Form\ConfirmFormHelper; use Drupal\Core\Form\ConfirmFormInterface; use Symfony\Component\HttpFoundation\Request; @@ -85,24 +85,8 @@ protected function actions(array $form, array &$form_state) { $actions['submit']['#value'] = $this->getConfirmText(); unset($actions['delete']); - $path = $this->getCancelPath(); // Prepare cancel link. - $query = $this->getRequest()->query; - if ($query->has('destination')) { - $options = Url::parse($query->get('destination')); - } - elseif (is_array($path)) { - $options = $path; - } - else { - $options = array('path' => $path); - } - $actions['cancel'] = array( - '#type' => 'link', - '#title' => $this->getCancelText(), - '#href' => $options['path'], - '#options' => $options, - ); + $actions['cancel'] = ConfirmFormHelper::buildCancelLink($this, $this->getRequest()); return $actions; } diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 3060909..5691d8d 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -397,6 +397,33 @@ public function getAdminPath($entity_type, $bundle) { } /** + * Returns the route information for an entity type's bundle. + * + * @param string $entity_type + * The entity type. + * @param string $bundle + * The name of the bundle. + * + * @return array + * An associative array with the following keys: + * - route_name: The name of the route. + * - route_parameters: (optional) An associative array of parameter names + * and values. + */ + public function getAdminRouteInfo($entity_type, $bundle) { + $entity_info = $this->getDefinition($entity_type); + if (isset($entity_info['bundle_prefix'])) { + $bundle = str_replace($entity_info['bundle_prefix'], '', $bundle); + } + return array( + 'route_name' => 'field_ui.overview.' . $entity_type, + 'route_parameters' => array( + 'bundle' => $bundle, + ) + ); + } + + /** * Gets an array of entity field definitions. * * If a bundle is passed, fields specific to this bundle are included. Entity diff --git a/core/lib/Drupal/Core/Entity/EntityNGConfirmFormBase.php b/core/lib/Drupal/Core/Entity/EntityNGConfirmFormBase.php index 742e379..0d60b72 100644 --- a/core/lib/Drupal/Core/Entity/EntityNGConfirmFormBase.php +++ b/core/lib/Drupal/Core/Entity/EntityNGConfirmFormBase.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Entity; -use Drupal\Component\Utility\Url; +use Drupal\Core\Form\ConfirmFormHelper; use Drupal\Core\Form\ConfirmFormInterface; /** @@ -92,24 +92,9 @@ protected function actions(array $form, array &$form_state) { $actions['submit']['#value'] = $this->getConfirmText(); unset($actions['delete']); - $path = $this->getCancelPath(); // Prepare cancel link. - $query = $this->getRequest()->query; - if ($query->has('destination')) { - $options = Url::parse($query->get('destination')); - } - elseif (is_array($path)) { - $options = $path; - } - else { - $options = array('path' => $path); - } - $actions['cancel'] = array( - '#type' => 'link', - '#title' => $this->getCancelText(), - '#href' => $options['path'], - '#options' => $options, - ); + $actions['cancel'] = ConfirmFormHelper::buildCancelLink($this, $this->getRequest()); + return $actions; } diff --git a/core/lib/Drupal/Core/Form/ConfirmFormBase.php b/core/lib/Drupal/Core/Form/ConfirmFormBase.php index 89e3ab7..ec0e5ce 100644 --- a/core/lib/Drupal/Core/Form/ConfirmFormBase.php +++ b/core/lib/Drupal/Core/Form/ConfirmFormBase.php @@ -7,8 +7,6 @@ namespace Drupal\Core\Form; -use Drupal\Component\Utility\Url; - /** * Provides an generic base class for a confirmation form. */ @@ -46,19 +44,6 @@ public function getFormName() { * {@inheritdoc} */ public function buildForm(array $form, array &$form_state) { - $path = $this->getCancelPath(); - // Prepare cancel link. - $query = $this->getRequest()->query; - if ($query->has('destination')) { - $options = Url::parse($query->get('destination')); - } - elseif (is_array($path)) { - $options = $path; - } - else { - $options = array('path' => $path); - } - drupal_set_title($this->getQuestion(), PASS_THROUGH); $form['#attributes']['class'][] = 'confirmation'; @@ -70,12 +55,9 @@ public function buildForm(array $form, array &$form_state) { '#type' => 'submit', '#value' => $this->getConfirmText(), ); - $form['actions']['cancel'] = array( - '#type' => 'link', - '#title' => $this->getCancelText(), - '#href' => $options['path'], - '#options' => $options, - ); + + $form['actions']['cancel'] = ConfirmFormHelper::buildCancelLink($this, $this->getRequest()); + // By default, render the form using theme_confirm_form(). if (!isset($form['#theme'])) { $form['#theme'] = 'confirm_form'; diff --git a/core/lib/Drupal/Core/Form/ConfirmFormHelper.php b/core/lib/Drupal/Core/Form/ConfirmFormHelper.php new file mode 100644 index 0000000..f2b4f25 --- /dev/null +++ b/core/lib/Drupal/Core/Form/ConfirmFormHelper.php @@ -0,0 +1,67 @@ +query; + // If a destination is specified, that serves as the cancel link. + if ($query->has('destination')) { + $options = Url::parse($query->get('destination')); + $link = array( + '#href' => $options['path'], + '#options' => $options, + ); + } + // Check for a route-based cancel link. + elseif ($route = $form->getCancelRoute()) { + if (empty($route['route_name'])) { + throw new \UnexpectedValueException(String::format('Missing route name in !class::getCancelRoute().', array('!class' => get_class($form)))); + } + // Ensure there is something to pass as the params and options. + $route += array( + 'route_parameters' => array(), + 'options' => array(), + ); + $link = array( + '#route_name' => $route['route_name'], + '#route_parameters' => $route['route_parameters'], + '#options' => $route['options'], + ); + } + + $link['#type'] = 'link'; + $link['#title'] = $form->getCancelText(); + return $link; + } + +} diff --git a/core/lib/Drupal/Core/Form/ConfirmFormInterface.php b/core/lib/Drupal/Core/Form/ConfirmFormInterface.php index 5c34f9a..0813cb7 100644 --- a/core/lib/Drupal/Core/Form/ConfirmFormInterface.php +++ b/core/lib/Drupal/Core/Form/ConfirmFormInterface.php @@ -21,17 +21,18 @@ public function getQuestion(); /** - * Returns the page to go to if the user cancels the action. + * Returns the route to go to if the user cancels the action. * - * @return string|array - * This can be either: - * - A string containing a Drupal path. - * - An associative array with a 'path' key. Additional array values are - * passed as the $options parameter to l(). - * If the 'destination' query parameter is set in the URL when viewing a - * confirmation form, that value will be used instead of this path. + * @return array + * An associative array with the following keys: + * - route_name: The name of the route. + * - route_parameters: (optional) An associative array of parameter names + * and values. + * - options: (optional) An associative array of additional options. See + * \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute() for + * comprehensive documentation. */ - public function getCancelPath(); + public function getCancelRoute(); /** * Returns additional text to display as a description. diff --git a/core/modules/action/lib/Drupal/action/Form/ActionDeleteForm.php b/core/modules/action/lib/Drupal/action/Form/ActionDeleteForm.php index 45c8649..23e8894 100644 --- a/core/modules/action/lib/Drupal/action/Form/ActionDeleteForm.php +++ b/core/modules/action/lib/Drupal/action/Form/ActionDeleteForm.php @@ -31,8 +31,10 @@ public function getConfirmText() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/config/system/actions'; + public function getCancelRoute() { + return array( + 'route_name' => 'action_admin', + ); } /** diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Form/CategoryDeleteForm.php b/core/modules/aggregator/lib/Drupal/aggregator/Form/CategoryDeleteForm.php index c8c28e7..c27dd65 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Form/CategoryDeleteForm.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Form/CategoryDeleteForm.php @@ -85,8 +85,10 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/config/services/aggregator'; + public function getCancelRoute() { + return array( + 'route_name' => 'aggregator_admin_overview', + ); } /** diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Form/FeedDeleteForm.php b/core/modules/aggregator/lib/Drupal/aggregator/Form/FeedDeleteForm.php index 2fd227d..1ea3f5a 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Form/FeedDeleteForm.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Form/FeedDeleteForm.php @@ -24,8 +24,10 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/config/services/aggregator'; + public function getCancelRoute() { + return array( + 'route_name' => 'aggregator_admin_overview', + ); } /** diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Form/FeedItemsRemoveForm.php b/core/modules/aggregator/lib/Drupal/aggregator/Form/FeedItemsRemoveForm.php index 5dd23dc..6ef34d6 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Form/FeedItemsRemoveForm.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Form/FeedItemsRemoveForm.php @@ -24,8 +24,10 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/config/services/aggregator'; + public function getCancelRoute() { + return array( + 'route_name' => 'aggregator_admin_overview', + ); } /** diff --git a/core/modules/ban/lib/Drupal/ban/Form/BanDelete.php b/core/modules/ban/lib/Drupal/ban/Form/BanDelete.php index d64a40f..c23feb5 100644 --- a/core/modules/ban/lib/Drupal/ban/Form/BanDelete.php +++ b/core/modules/ban/lib/Drupal/ban/Form/BanDelete.php @@ -67,8 +67,10 @@ public function getConfirmText() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/config/people/ban'; + public function getCancelRoute() { + return array( + 'route_name' => 'ban_admin_page', + ); } /** diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Form/CustomBlockDeleteForm.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Form/CustomBlockDeleteForm.php index 0cc6f05..8c6f012 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Form/CustomBlockDeleteForm.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Form/CustomBlockDeleteForm.php @@ -25,8 +25,10 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/structure/block'; + public function getCancelRoute() { + return array( + 'route_name' => 'block_admin_display', + ); } /** diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Form/CustomBlockTypeDeleteForm.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Form/CustomBlockTypeDeleteForm.php index eac3ab6..a4b827a 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Form/CustomBlockTypeDeleteForm.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Form/CustomBlockTypeDeleteForm.php @@ -52,8 +52,10 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/structure/custom-blocks/types'; + public function getCancelRoute() { + return array( + 'route_name' => 'custom_block_type_list', + ); } /** diff --git a/core/modules/block/lib/Drupal/block/Form/BlockDeleteForm.php b/core/modules/block/lib/Drupal/block/Form/BlockDeleteForm.php index 9286a24..e6ccfb2 100644 --- a/core/modules/block/lib/Drupal/block/Form/BlockDeleteForm.php +++ b/core/modules/block/lib/Drupal/block/Form/BlockDeleteForm.php @@ -24,8 +24,10 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/structure/block'; + public function getCancelRoute() { + return array( + 'route_name' => 'block_admin_display', + ); } /** diff --git a/core/modules/comment/lib/Drupal/comment/Form/ConfirmDeleteMultiple.php b/core/modules/comment/lib/Drupal/comment/Form/ConfirmDeleteMultiple.php index c3cebf7..08fb6d0 100644 --- a/core/modules/comment/lib/Drupal/comment/Form/ConfirmDeleteMultiple.php +++ b/core/modules/comment/lib/Drupal/comment/Form/ConfirmDeleteMultiple.php @@ -70,8 +70,7 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/content/comment'; + public function getCancelRoute() { } /** @@ -112,7 +111,11 @@ public function buildForm(array $form, array &$form_state, Request $request = NU $form_state['redirect'] = 'admin/content/comment'; } - return parent::buildForm($form, $form_state, $request); + $form = parent::buildForm($form, $form_state); + + // @todo Convert to getCancelRoute() after http://drupal.org/node/1986606. + $form['actions']['cancel']['#href'] = 'admin/content/comment'; + return $form; } /** diff --git a/core/modules/comment/lib/Drupal/comment/Form/DeleteForm.php b/core/modules/comment/lib/Drupal/comment/Form/DeleteForm.php index fd86ddf..53e1741 100644 --- a/core/modules/comment/lib/Drupal/comment/Form/DeleteForm.php +++ b/core/modules/comment/lib/Drupal/comment/Form/DeleteForm.php @@ -26,8 +26,19 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'node/' . $this->entity->nid->target_id; + protected function actions(array $form, array &$form_state) { + $actions = parent::actions($form, $form_state); + + // @todo Convert to getCancelRoute() after http://drupal.org/node/1987778. + $actions['cancel']['#href'] = 'node/' . $this->entity->nid->target_id; + + return $actions; + } + + /** + * {@inheritdoc} + */ + public function getCancelRoute() { } /** diff --git a/core/modules/config/tests/config_test/lib/Drupal/config_test/Form/ConfigTestDeleteForm.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/Form/ConfigTestDeleteForm.php index c4e3d53..6f90d2a 100644 --- a/core/modules/config/tests/config_test/lib/Drupal/config_test/Form/ConfigTestDeleteForm.php +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/Form/ConfigTestDeleteForm.php @@ -31,8 +31,10 @@ public function getConfirmText() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/structure/config_test'; + public function getCancelRoute() { + return array( + 'route_name' => 'config_test_list_page', + ); } /** diff --git a/core/modules/contact/lib/Drupal/contact/Form/CategoryDeleteForm.php b/core/modules/contact/lib/Drupal/contact/Form/CategoryDeleteForm.php index 75988a7..3cbdd7a 100644 --- a/core/modules/contact/lib/Drupal/contact/Form/CategoryDeleteForm.php +++ b/core/modules/contact/lib/Drupal/contact/Form/CategoryDeleteForm.php @@ -24,8 +24,10 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/structure/contact'; + public function getCancelRoute() { + return array( + 'route_name' => 'contact_category_list', + ); } /** diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Form/TranslatableForm.php b/core/modules/content_translation/lib/Drupal/content_translation/Form/TranslatableForm.php index 7d844eb..6ab01af 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Form/TranslatableForm.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Form/TranslatableForm.php @@ -66,8 +66,10 @@ public function getDescription() { /** * {@inheritdoc} */ - public function getCancelPath() { - return ''; + public function getCancelRoute() { + return array( + 'route_name' => '', + ); } /** diff --git a/core/modules/entity/lib/Drupal/entity/Form/EntityDisplayModeDeleteForm.php b/core/modules/entity/lib/Drupal/entity/Form/EntityDisplayModeDeleteForm.php index 1de637a..ec12e68 100644 --- a/core/modules/entity/lib/Drupal/entity/Form/EntityDisplayModeDeleteForm.php +++ b/core/modules/entity/lib/Drupal/entity/Form/EntityDisplayModeDeleteForm.php @@ -17,9 +17,10 @@ class EntityDisplayModeDeleteForm extends EntityConfirmFormBase { /** * {@inheritdoc} */ - public function getCancelPath() { - $short_type = str_replace('_mode', '', $this->entity->entityType()); - return "admin/structure/display-modes/$short_type"; + public function getCancelRoute() { + return array( + 'route_name' => 'entity_' . $this->entity->entityType() . '.list', + ); } /** diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php index afaa1d5..2924c35 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php @@ -59,8 +59,8 @@ public function getConfirmText() { /** * {@inheritdoc} */ - public function getCancelPath() { - return $this->entityManager->getAdminPath($this->entity->entity_type, $this->entity->bundle) . '/fields'; + public function getCancelRoute() { + return $this->entityManager->getAdminRouteInfo($this->entity->entity_type, $this->entity->bundle); } /** diff --git a/core/modules/filter/lib/Drupal/filter/Form/FilterDisableForm.php b/core/modules/filter/lib/Drupal/filter/Form/FilterDisableForm.php index 2759b2b..01dc651 100644 --- a/core/modules/filter/lib/Drupal/filter/Form/FilterDisableForm.php +++ b/core/modules/filter/lib/Drupal/filter/Form/FilterDisableForm.php @@ -24,8 +24,10 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/config/content/formats'; + public function getCancelRoute() { + return array( + 'route_name' => 'filter_admin_overview', + ); } /** diff --git a/core/modules/forum/lib/Drupal/forum/Form/DeleteForm.php b/core/modules/forum/lib/Drupal/forum/Form/DeleteForm.php index 299366c..33cc069 100644 --- a/core/modules/forum/lib/Drupal/forum/Form/DeleteForm.php +++ b/core/modules/forum/lib/Drupal/forum/Form/DeleteForm.php @@ -39,8 +39,7 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/structure/forum'; + public function getCancelRoute() { } /** @@ -56,7 +55,11 @@ public function getConfirmText() { public function buildForm(array $form, array &$form_state, TermInterface $taxonomy_term = NULL) { $this->taxonomyTerm = $taxonomy_term; - return parent::buildForm($form, $form_state); + $form = parent::buildForm($form, $form_state); + + // @todo Convert to getCancelRoute() after http://drupal.org/node/1974210. + $form['actions']['cancel']['#href'] = 'admin/structure/forum'; + return $form; } /** diff --git a/core/modules/image/lib/Drupal/image/Form/ImageEffectDeleteForm.php b/core/modules/image/lib/Drupal/image/Form/ImageEffectDeleteForm.php index 5e8b762..32d07d9 100644 --- a/core/modules/image/lib/Drupal/image/Form/ImageEffectDeleteForm.php +++ b/core/modules/image/lib/Drupal/image/Form/ImageEffectDeleteForm.php @@ -46,8 +46,13 @@ public function getConfirmText() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/config/media/image-styles/manage/' . $this->imageStyle->id(); + public function getCancelRoute() { + return array( + 'route_name' => 'image_style_edit', + 'route_parameters' => array( + 'image_style' => $this->imageStyle->id(), + ), + ); } /** diff --git a/core/modules/image/lib/Drupal/image/Form/ImageStyleDeleteForm.php b/core/modules/image/lib/Drupal/image/Form/ImageStyleDeleteForm.php index 315fdef..5f96271 100644 --- a/core/modules/image/lib/Drupal/image/Form/ImageStyleDeleteForm.php +++ b/core/modules/image/lib/Drupal/image/Form/ImageStyleDeleteForm.php @@ -31,8 +31,10 @@ public function getConfirmText() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/config/media/image-styles'; + public function getCancelRoute() { + return array( + 'route_name' => 'image_style_list', + ); } /** diff --git a/core/modules/language/lib/Drupal/language/Form/LanguageDeleteForm.php b/core/modules/language/lib/Drupal/language/Form/LanguageDeleteForm.php index b6003c5..164f271 100644 --- a/core/modules/language/lib/Drupal/language/Form/LanguageDeleteForm.php +++ b/core/modules/language/lib/Drupal/language/Form/LanguageDeleteForm.php @@ -55,8 +55,10 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/config/regional/language'; + public function getCancelRoute() { + return array( + 'route_name' => 'language_admin_overview', + ); } /** diff --git a/core/modules/language/lib/Drupal/language/Form/NegotiationBrowserDeleteForm.php b/core/modules/language/lib/Drupal/language/Form/NegotiationBrowserDeleteForm.php index cb8db31..29de4ce 100644 --- a/core/modules/language/lib/Drupal/language/Form/NegotiationBrowserDeleteForm.php +++ b/core/modules/language/lib/Drupal/language/Form/NegotiationBrowserDeleteForm.php @@ -32,8 +32,7 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/config/regional/language/detection/browser'; + public function getCancelRoute() { } /** @@ -49,7 +48,11 @@ public function getFormID() { public function buildForm(array $form, array &$form_state, $browser_langcode = NULL) { $this->browserLangcode = $browser_langcode; - return parent::buildForm($form, $form_state); + $form = parent::buildForm($form, $form_state); + + // @todo Convert to getCancelRoute() after http://drupal.org/node/2082071. + $form['actions']['cancel']['#href'] = 'admin/config/regional/language/detection/browser'; + return $form; } /** diff --git a/core/modules/menu/lib/Drupal/menu/Form/MenuDeleteForm.php b/core/modules/menu/lib/Drupal/menu/Form/MenuDeleteForm.php index ce8b5d1..511744b 100644 --- a/core/modules/menu/lib/Drupal/menu/Form/MenuDeleteForm.php +++ b/core/modules/menu/lib/Drupal/menu/Form/MenuDeleteForm.php @@ -64,8 +64,13 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/structure/menu/manage/' . $this->entity->id(); + public function getCancelRoute() { + return array( + 'route_name' => 'menu_menu_edit', + 'route_parameters' => array( + 'menu' => $this->entity->id(), + ), + ); } /** diff --git a/core/modules/menu/lib/Drupal/menu/Form/MenuLinkDeleteForm.php b/core/modules/menu/lib/Drupal/menu/Form/MenuLinkDeleteForm.php index ffb2af5..cb2a819 100644 --- a/core/modules/menu/lib/Drupal/menu/Form/MenuLinkDeleteForm.php +++ b/core/modules/menu/lib/Drupal/menu/Form/MenuLinkDeleteForm.php @@ -24,8 +24,13 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/structure/menu/manage/' . $this->entity->menu_name; + public function getCancelRoute() { + return array( + 'route_name' => 'menu_menu_edit', + 'route_parameters' => array( + 'menu' => $this->entity->menu_name, + ), + ); } /** diff --git a/core/modules/menu/lib/Drupal/menu/Form/MenuLinkResetForm.php b/core/modules/menu/lib/Drupal/menu/Form/MenuLinkResetForm.php index d079b51..f0b6ec3 100644 --- a/core/modules/menu/lib/Drupal/menu/Form/MenuLinkResetForm.php +++ b/core/modules/menu/lib/Drupal/menu/Form/MenuLinkResetForm.php @@ -24,8 +24,13 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/structure/menu/manage/' . $this->entity->menu_name; + public function getCancelRoute() { + return array( + 'route_name' => 'menu_menu_edit', + 'route_parameters' => array( + 'menu' => $this->entity->menu_name, + ), + ); } /** diff --git a/core/modules/node/lib/Drupal/node/Form/DeleteMultiple.php b/core/modules/node/lib/Drupal/node/Form/DeleteMultiple.php index 849dd1a..3d94f52 100644 --- a/core/modules/node/lib/Drupal/node/Form/DeleteMultiple.php +++ b/core/modules/node/lib/Drupal/node/Form/DeleteMultiple.php @@ -81,8 +81,7 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/content'; + public function getCancelRoute() { } /** @@ -98,7 +97,7 @@ public function getConfirmText() { public function buildForm(array $form, array &$form_state) { $this->nodes = $this->tempStoreFactory->get('node_multiple_delete_confirm')->get($GLOBALS['user']->id()); if (empty($this->nodes)) { - return new RedirectResponse(url($this->getCancelPath(), array('absolute' => TRUE))); + return new RedirectResponse(url('admin/content', array('absolute' => TRUE))); } $form['nodes'] = array( @@ -107,7 +106,11 @@ public function buildForm(array $form, array &$form_state) { return String::checkPlain($node->label()); }, $this->nodes), ); - return parent::buildForm($form, $form_state); + $form = parent::buildForm($form, $form_state); + + // @todo Convert to getCancelRoute() after http://drupal.org/node/2021161. + $form['actions']['cancel']['#href'] = 'admin/content'; + return $form; } /** diff --git a/core/modules/node/lib/Drupal/node/Form/NodeDeleteForm.php b/core/modules/node/lib/Drupal/node/Form/NodeDeleteForm.php index 299f780..29db847 100644 --- a/core/modules/node/lib/Drupal/node/Form/NodeDeleteForm.php +++ b/core/modules/node/lib/Drupal/node/Form/NodeDeleteForm.php @@ -64,9 +64,20 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { + protected function actions(array $form, array &$form_state) { + $actions = parent::actions($form, $form_state); + + // @todo Convert to getCancelRoute() after http://drupal.org/node/1987778. $uri = $this->entity->uri(); - return $this->urlGenerator->generateFromPath($uri['path'], $uri['options']); + $actions['cancel']['#href'] = $this->urlGenerator->generateFromPath($uri['path'], $uri['options']); + + return $actions; + } + + /** + * {@inheritdoc} + */ + public function getCancelRoute() { } /** diff --git a/core/modules/node/lib/Drupal/node/Form/NodeRevisionDeleteForm.php b/core/modules/node/lib/Drupal/node/Form/NodeRevisionDeleteForm.php index ad0201e..60a929c 100644 --- a/core/modules/node/lib/Drupal/node/Form/NodeRevisionDeleteForm.php +++ b/core/modules/node/lib/Drupal/node/Form/NodeRevisionDeleteForm.php @@ -92,8 +92,7 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'node/' . $this->revision->id() . '/revisions'; + public function getCancelRoute() { } /** @@ -108,7 +107,11 @@ public function getConfirmText() { */ public function buildForm(array $form, array &$form_state, $node_revision = NULL) { $this->revision = $this->nodeStorage->loadRevision($node_revision); - return parent::buildForm($form, $form_state); + $form = parent::buildForm($form, $form_state); + + // @todo Convert to getCancelRoute() after http://drupal.org/node/1863906. + $form['actions']['cancel']['#href'] = 'node/' . $this->revision->id() . '/revisions'; + return $form; } /** diff --git a/core/modules/node/lib/Drupal/node/Form/NodeRevisionRevertForm.php b/core/modules/node/lib/Drupal/node/Form/NodeRevisionRevertForm.php index 765a1eb..cbbefc0 100644 --- a/core/modules/node/lib/Drupal/node/Form/NodeRevisionRevertForm.php +++ b/core/modules/node/lib/Drupal/node/Form/NodeRevisionRevertForm.php @@ -68,8 +68,7 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'node/' . $this->revision->id() . '/revisions'; + public function getCancelRoute() { } /** @@ -91,7 +90,11 @@ public function getDescription() { */ public function buildForm(array $form, array &$form_state, $node_revision = NULL) { $this->revision = $this->nodeStorage->loadRevision($node_revision); - return parent::buildForm($form, $form_state); + $form = parent::buildForm($form, $form_state); + + // @todo Convert to getCancelRoute() after http://drupal.org/node/1863906. + $form['actions']['cancel']['#href'] = 'node/' . $this->revision->id() . '/revisions'; + return $form; } /** diff --git a/core/modules/node/lib/Drupal/node/Form/NodeTypeDeleteConfirm.php b/core/modules/node/lib/Drupal/node/Form/NodeTypeDeleteConfirm.php index b7bda70..3793c71 100644 --- a/core/modules/node/lib/Drupal/node/Form/NodeTypeDeleteConfirm.php +++ b/core/modules/node/lib/Drupal/node/Form/NodeTypeDeleteConfirm.php @@ -52,8 +52,10 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/structure/types'; + public function getCancelRoute() { + return array( + 'route_name' => 'node_overview_types', + ); } /** @@ -87,7 +89,7 @@ public function submit(array $form, array &$form_state) { drupal_set_message(t('The content type %name has been deleted.', $t_args)); watchdog('node', 'Deleted content type %name.', $t_args, WATCHDOG_NOTICE); - $form_state['redirect'] = $this->getCancelPath(); + $form_state['redirect'] = 'admin/structure/types'; } } diff --git a/core/modules/node/lib/Drupal/node/Form/RebuildPermissionsForm.php b/core/modules/node/lib/Drupal/node/Form/RebuildPermissionsForm.php index d104fab..a743064 100644 --- a/core/modules/node/lib/Drupal/node/Form/RebuildPermissionsForm.php +++ b/core/modules/node/lib/Drupal/node/Form/RebuildPermissionsForm.php @@ -28,8 +28,10 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/reports/status'; + public function getCancelRoute() { + return array( + 'route_name' => 'system_status', + ); } /** diff --git a/core/modules/path/lib/Drupal/path/Form/DeleteForm.php b/core/modules/path/lib/Drupal/path/Form/DeleteForm.php index 3f16e0e..8a2d315 100644 --- a/core/modules/path/lib/Drupal/path/Form/DeleteForm.php +++ b/core/modules/path/lib/Drupal/path/Form/DeleteForm.php @@ -65,10 +65,9 @@ public function getQuestion() { } /** - * Implements \Drupal\Core\Form\ConfirmFormBase::getCancelPath(). + * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/config/search/path'; + public function getCancelRoute() { } /** @@ -77,7 +76,11 @@ public function getCancelPath() { public function buildForm(array $form, array &$form_state, $pid = NULL) { $this->pathAlias = $this->path->load(array('pid' => $pid)); - return parent::buildForm($form, $form_state); + $form = parent::buildForm($form, $form_state); + + // @todo Convert to getCancelRoute() after http://drupal.org/node/1987802. + $form['actions']['cancel']['#href'] = 'admin/config/search/path'; + return $form; } /** diff --git a/core/modules/picture/lib/Drupal/picture/Form/PictureMappingDeleteForm.php b/core/modules/picture/lib/Drupal/picture/Form/PictureMappingDeleteForm.php index ef3389f..1ed16e1 100644 --- a/core/modules/picture/lib/Drupal/picture/Form/PictureMappingDeleteForm.php +++ b/core/modules/picture/lib/Drupal/picture/Form/PictureMappingDeleteForm.php @@ -21,8 +21,10 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/config/media/picturemapping'; + public function getCancelRoute() { + return array( + 'route_name' => 'picture_mapping_page', + ); } /** diff --git a/core/modules/search/lib/Drupal/search/Form/ReindexConfirm.php b/core/modules/search/lib/Drupal/search/Form/ReindexConfirm.php index 0984b0b..80c2417 100644 --- a/core/modules/search/lib/Drupal/search/Form/ReindexConfirm.php +++ b/core/modules/search/lib/Drupal/search/Form/ReindexConfirm.php @@ -50,10 +50,12 @@ public function getCancelText() { } /** - * Implements \Drupal\Core\Form\ConfirmFormBase::getCancelPath(). + * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/config/search/settings'; + public function getCancelRoute() { + return array( + 'route_name' => 'search_settings', + ); } /** diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Form/LinkDelete.php b/core/modules/shortcut/lib/Drupal/shortcut/Form/LinkDelete.php index 76a62ae..de8a8dc 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/Form/LinkDelete.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/Form/LinkDelete.php @@ -39,8 +39,13 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/config/user-interface/shortcut/manage/' . $this->menuLink->menu_name; + public function getCancelRoute() { + return array( + 'route_name' => 'shortcut_set_customize', + 'route_parameters' => array( + 'shortcut_set' => str_replace('shortcut-', '', $this->menuLink->menu_name), + ), + ); } /** diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Form/ShortcutSetDeleteForm.php b/core/modules/shortcut/lib/Drupal/shortcut/Form/ShortcutSetDeleteForm.php index a3b0f61..bab133f 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/Form/ShortcutSetDeleteForm.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/Form/ShortcutSetDeleteForm.php @@ -59,8 +59,13 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/config/user-interface/shortcut/manage/' . $this->entity->id(); + public function getCancelRoute() { + return array( + 'route_name' => 'shortcut_set_customize', + 'route_parameters' => array( + 'shortcut_set' => $this->entity->id(), + ), + ); } /** diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index 7b9302a..28ff813 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -2361,7 +2361,11 @@ protected function assertUrl($path, array $options = array(), $message = '', $gr )); } $options['absolute'] = TRUE; - return $this->assertEqual($this->getUrl(), $this->container->get('url_generator')->generateFromPath($path, $options), $message, $group); + // Paths in query strings can be encoded or decoded with no functional + // difference, decode them for comparison purposes. + $actual_url = str_replace('%2F', '/', $this->getUrl()); + $expected_url = str_replace('%2F', '/', $this->container->get('url_generator')->generateFromPath($path, $options)); + return $this->assertEqual($actual_url, $expected_url, $message, $group); } /** diff --git a/core/modules/system/lib/Drupal/system/Form/DateFormatDeleteForm.php b/core/modules/system/lib/Drupal/system/Form/DateFormatDeleteForm.php index 97a4020..733c870 100644 --- a/core/modules/system/lib/Drupal/system/Form/DateFormatDeleteForm.php +++ b/core/modules/system/lib/Drupal/system/Form/DateFormatDeleteForm.php @@ -62,8 +62,10 @@ public function getConfirmText() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/config/regional/date-time'; + public function getCancelRoute() { + return array( + 'route_name' => 'date_format_list', + ); } /** diff --git a/core/modules/system/lib/Drupal/system/Form/DateFormatLocalizeResetForm.php b/core/modules/system/lib/Drupal/system/Form/DateFormatLocalizeResetForm.php index 8bfa07e..832afd0 100644 --- a/core/modules/system/lib/Drupal/system/Form/DateFormatLocalizeResetForm.php +++ b/core/modules/system/lib/Drupal/system/Form/DateFormatLocalizeResetForm.php @@ -76,8 +76,10 @@ public function getConfirmText() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/config/regional/date-time/locale'; + public function getCancelRoute() { + return array( + 'route_name' => 'date_format_language_overview', + ); } /** diff --git a/core/modules/system/lib/Drupal/system/Form/ModulesListConfirmForm.php b/core/modules/system/lib/Drupal/system/Form/ModulesListConfirmForm.php index d674b18..26e5349 100644 --- a/core/modules/system/lib/Drupal/system/Form/ModulesListConfirmForm.php +++ b/core/modules/system/lib/Drupal/system/Form/ModulesListConfirmForm.php @@ -73,8 +73,10 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/modules'; + public function getCancelRoute() { + return array( + 'route_name' => 'system_modules_list', + ); } /** @@ -107,7 +109,7 @@ public function buildForm(array $form, array &$form_state) { // Redirect to the modules list page if the key value store is empty. if (!$this->modules) { - return new RedirectResponse(url($this->getCancelPath(), array('absolute' => TRUE))); + return new RedirectResponse($this->getUrlGenerator()->generate('system_modules_list', array(), TRUE)); } $items = array(); @@ -161,7 +163,7 @@ public function submitForm(array &$form, array &$form_state) { drupal_set_message($this->t('The configuration options have been saved.')); } - $form_state['redirect'] = $this->getCancelPath(); + $form_state['redirect'] = 'admin/modules'; } } diff --git a/core/modules/system/lib/Drupal/system/Form/ModulesUninstallConfirmForm.php b/core/modules/system/lib/Drupal/system/Form/ModulesUninstallConfirmForm.php index be3d19f..73da26e 100644 --- a/core/modules/system/lib/Drupal/system/Form/ModulesUninstallConfirmForm.php +++ b/core/modules/system/lib/Drupal/system/Form/ModulesUninstallConfirmForm.php @@ -80,8 +80,10 @@ public function getConfirmText() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/modules/uninstall'; + public function getCancelRoute() { + return array( + 'route_name' => 'system_modules_uninstall', + ); } /** diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/ConfirmFormArrayPathTestForm.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/ConfirmFormArrayPathTestForm.php index d399ddf..3a3e02c 100644 --- a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/ConfirmFormArrayPathTestForm.php +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/ConfirmFormArrayPathTestForm.php @@ -22,11 +22,13 @@ public function getFormID() { /** * {@inheritdoc} */ - public function getCancelPath() { + public function getCancelRoute() { return array( - 'path' => 'admin', - 'query' => array( - 'destination' => 'admin/config', + 'route_name' => 'system_admin', + 'options' => array( + 'query' => array( + 'destination' => 'admin/config', + ), ), ); } diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/ConfirmFormTestForm.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/ConfirmFormTestForm.php index d2f0b93..e7f40fd 100644 --- a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/ConfirmFormTestForm.php +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/ConfirmFormTestForm.php @@ -31,8 +31,10 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin'; + public function getCancelRoute() { + return array( + 'route_name' => 'system_admin', + ); } /** diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Form/TermDeleteForm.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/TermDeleteForm.php index f7a9ebb..b3a7c9f 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Form/TermDeleteForm.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/TermDeleteForm.php @@ -60,8 +60,10 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/structure/taxonomy'; + public function getCancelRoute() { + return array( + 'route_name' => 'taxonomy_vocabulary_list', + ); } /** diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Form/VocabularyDeleteForm.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/VocabularyDeleteForm.php index 7ec0aa7..b598358 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Form/VocabularyDeleteForm.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/VocabularyDeleteForm.php @@ -32,8 +32,10 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/structure/taxonomy'; + public function getCancelRoute() { + return array( + 'route_name' => 'taxonomy_vocabulary_list', + ); } /** diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Form/VocabularyResetForm.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/VocabularyResetForm.php index 4f0740f..a44aeab 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Form/VocabularyResetForm.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/VocabularyResetForm.php @@ -56,8 +56,13 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/structure/taxonomy/manage/' . $this->entity->id(); + public function getCancelRoute() { + return array( + 'route_name' => 'taxonomy_overview_terms', + 'route_parameters' => array( + 'taxonomy_vocabulary' => $this->entity->id(), + ), + ); } /** diff --git a/core/modules/user/lib/Drupal/user/Form/UserRoleDelete.php b/core/modules/user/lib/Drupal/user/Form/UserRoleDelete.php index fec4793..2e8f07a 100644 --- a/core/modules/user/lib/Drupal/user/Form/UserRoleDelete.php +++ b/core/modules/user/lib/Drupal/user/Form/UserRoleDelete.php @@ -24,8 +24,10 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/people/roles'; + public function getCancelRoute() { + return array( + 'route_name' => 'user_role_list', + ); } /** diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Form/BreakLockForm.php b/core/modules/views_ui/lib/Drupal/views_ui/Form/BreakLockForm.php index 7673325..38958be 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/Form/BreakLockForm.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/Form/BreakLockForm.php @@ -84,8 +84,13 @@ public function getDescription() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/structure/views/view/' . $this->entity->id(); + public function getCancelRoute() { + return array( + 'route_name' => 'views_ui.edit', + 'route_parameters' => array( + 'view' => $this->entity->id(), + ), + ); } /** diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewDeleteFormController.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewDeleteFormController.php index 1815ec5..251dc6f 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewDeleteFormController.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewDeleteFormController.php @@ -24,8 +24,10 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelPath() { - return 'admin/structure/views'; + public function getCancelRoute() { + return array( + 'route_name' => 'views_ui.list', + ); } /** diff --git a/core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php b/core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php new file mode 100644 index 0000000..5381bfb --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php @@ -0,0 +1,107 @@ + 'Confirm form helper test', + 'description' => 'Tests the confirm form helper class.', + 'group' => 'Form API', + ); + } + + /** + * Tests the cancel link title. + */ + public function testCancelLinkTitle() { + $cancel_text = 'Cancel text'; + $form = $this->getMock('Drupal\Core\Form\ConfirmFormInterface'); + $form->expects($this->any()) + ->method('getCancelText') + ->will($this->returnValue($cancel_text)); + + $link = ConfirmFormHelper::buildCancelLink($form, new Request()); + $this->assertSame($cancel_text, $link['#title']); + } + + /** + * Tests a cancel link route. + */ + public function testCancelLinkRoute() { + $cancel_route = array( + 'route_name' => 'foo_bar', + ); + $form = $this->getMock('Drupal\Core\Form\ConfirmFormInterface'); + $form->expects($this->any()) + ->method('getCancelRoute') + ->will($this->returnValue($cancel_route)); + $link = ConfirmFormHelper::buildCancelLink($form, new Request()); + $this->assertSame($cancel_route['route_name'], $link['#route_name']); + } + + /** + * Tests a cancel link route with parameters. + */ + public function testCancelLinkRouteWithParams() { + $cancel_route = array( + 'route_name' => 'foo_bar/{baz}', + 'route_parameters' => array( + 'baz' => 'banana', + ), + 'options' => array( + 'html' => TRUE, + ), + ); + $form = $this->getMock('Drupal\Core\Form\ConfirmFormInterface'); + $form->expects($this->any()) + ->method('getCancelRoute') + ->will($this->returnValue($cancel_route)); + $link = ConfirmFormHelper::buildCancelLink($form, new Request()); + $this->assertSame($cancel_route['route_name'], $link['#route_name']); + $this->assertSame($cancel_route['route_parameters'], $link['#route_parameters']); + $this->assertSame($cancel_route['options'], $link['#options']); + } + + /** + * Tests an invalid cancel link route. + * + * @expectedException \UnexpectedValueException + */ + public function testCancelLinkInvalidRoute() { + $form = $this->getMock('Drupal\Core\Form\ConfirmFormInterface'); + $form->expects($this->any()) + ->method('getCancelRoute') + ->will($this->returnValue(array('invalid' => 'foo_bar'))); + ConfirmFormHelper::buildCancelLink($form, new Request()); + } + + /** + * Tests a cancel link provided by the destination. + */ + public function testCancelLinkDestination() { + $query = array('destination' => 'baz'); + $form = $this->getMock('Drupal\Core\Form\ConfirmFormInterface'); + $link = ConfirmFormHelper::buildCancelLink($form, new Request($query)); + $this->assertSame($query['destination'], $link['#href']); + } + +}