Issue #1963394 by tim.plunkett, jibran, effulgentsia: Fixed ConfirmFormBase::getCancelPath() should allow for a route.
parent
670e43b51e
commit
ca7ae5992a
|
@ -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 @@ abstract class EntityConfirmFormBase extends EntityFormController implements Con
|
|||
$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;
|
||||
}
|
||||
|
||||
|
|
|
@ -410,6 +410,33 @@ class EntityManager extends PluginManagerBase {
|
|||
return $admin_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
|
|
@ -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 @@ abstract class EntityNGConfirmFormBase extends EntityFormControllerNG implements
|
|||
$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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 @@ abstract class ConfirmFormBase extends FormBase implements ConfirmFormInterface
|
|||
* {@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 @@ abstract class ConfirmFormBase extends FormBase implements ConfirmFormInterface
|
|||
'#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';
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Form\ConfirmFormHelper.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Form;
|
||||
|
||||
use Drupal\Component\Utility\String;
|
||||
use Drupal\Component\Utility\Url;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Provides common functionality to confirmation forms.
|
||||
*/
|
||||
class ConfirmFormHelper {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @throws \UnexpectedValueException
|
||||
* Ensures that \Drupal\Core\Form\ConfirmFormInterface::getCancelRoute()
|
||||
* returns an array containing a route name.
|
||||
*/
|
||||
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 = 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -21,17 +21,18 @@ interface ConfirmFormInterface extends FormInterface {
|
|||
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.
|
||||
|
|
|
@ -31,8 +31,10 @@ class ActionDeleteForm extends EntityConfirmFormBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/config/system/actions';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => 'action_admin',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -85,8 +85,10 @@ class CategoryDeleteForm extends ConfirmFormBase implements ContainerInjectionIn
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/config/services/aggregator';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => 'aggregator_admin_overview',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,8 +24,10 @@ class FeedDeleteForm extends EntityNGConfirmFormBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/config/services/aggregator';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => 'aggregator_admin_overview',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,8 +24,10 @@ class FeedItemsRemoveForm extends EntityNGConfirmFormBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/config/services/aggregator';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => 'aggregator_admin_overview',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -67,8 +67,10 @@ class BanDelete extends ConfirmFormBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/config/people/ban';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => 'ban_admin_page',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,8 +25,10 @@ class CustomBlockDeleteForm extends EntityNGConfirmFormBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/structure/block';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => 'block_admin_display',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -52,8 +52,10 @@ class CustomBlockTypeDeleteForm extends EntityConfirmFormBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/structure/block/custom-blocks/types';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => 'custom_block_type_list',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,8 +24,10 @@ class BlockDeleteForm extends EntityConfirmFormBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/structure/block';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => 'block_admin_display',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -70,8 +70,7 @@ class ConfirmDeleteMultiple extends ConfirmFormBase implements ContainerInjectio
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/content/comment';
|
||||
public function getCancelRoute() {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,7 +111,11 @@ class ConfirmDeleteMultiple extends ConfirmFormBase implements ContainerInjectio
|
|||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,8 +26,19 @@ class DeleteForm extends EntityNGConfirmFormBase {
|
|||
/**
|
||||
* {@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() {
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -31,8 +31,10 @@ class ConfigTestDeleteForm extends EntityConfirmFormBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/structure/config_test';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => 'config_test_list_page',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,8 +24,10 @@ class CategoryDeleteForm extends EntityConfirmFormBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/structure/contact';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => 'contact_category_list',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -66,8 +66,10 @@ class TranslatableForm extends ConfirmFormBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return '';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => '<front>',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -59,8 +59,8 @@ class FieldDeleteForm extends EntityConfirmFormBase {
|
|||
/**
|
||||
* {@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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,8 +24,10 @@ class FilterDisableForm extends EntityConfirmFormBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/config/content/formats';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => 'filter_admin_overview',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -39,8 +39,7 @@ class DeleteForm extends ConfirmFormBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/structure/forum';
|
||||
public function getCancelRoute() {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,7 +55,11 @@ class DeleteForm extends ConfirmFormBase {
|
|||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -46,8 +46,13 @@ class ImageEffectDeleteForm extends ConfirmFormBase {
|
|||
/**
|
||||
* {@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(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -31,8 +31,10 @@ class ImageStyleDeleteForm extends EntityConfirmFormBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/config/media/image-styles';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => 'image_style_list',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -55,8 +55,10 @@ class LanguageDeleteForm extends EntityConfirmFormBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/config/regional/language';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => 'language_admin_overview',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,8 +32,7 @@ class NegotiationBrowserDeleteForm extends ConfirmFormBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/config/regional/language/detection/browser';
|
||||
public function getCancelRoute() {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,7 +48,11 @@ class NegotiationBrowserDeleteForm extends ConfirmFormBase {
|
|||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -64,8 +64,13 @@ class MenuDeleteForm extends EntityConfirmFormBase {
|
|||
/**
|
||||
* {@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(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,8 +24,13 @@ class MenuLinkDeleteForm extends EntityConfirmFormBase {
|
|||
/**
|
||||
* {@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,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,8 +24,13 @@ class MenuLinkResetForm extends EntityConfirmFormBase {
|
|||
/**
|
||||
* {@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,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -81,8 +81,7 @@ class DeleteMultiple extends ConfirmFormBase implements ContainerInjectionInterf
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/content';
|
||||
public function getCancelRoute() {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -98,7 +97,7 @@ class DeleteMultiple extends ConfirmFormBase implements ContainerInjectionInterf
|
|||
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 @@ class DeleteMultiple extends ConfirmFormBase implements ContainerInjectionInterf
|
|||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -64,9 +64,20 @@ class NodeDeleteForm extends EntityNGConfirmFormBase {
|
|||
/**
|
||||
* {@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() {
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -92,8 +92,7 @@ class NodeRevisionDeleteForm extends ConfirmFormBase implements ContainerInjecti
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'node/' . $this->revision->id() . '/revisions';
|
||||
public function getCancelRoute() {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -108,7 +107,11 @@ class NodeRevisionDeleteForm extends ConfirmFormBase implements ContainerInjecti
|
|||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -68,8 +68,7 @@ class NodeRevisionRevertForm extends ConfirmFormBase implements ContainerInjecti
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'node/' . $this->revision->id() . '/revisions';
|
||||
public function getCancelRoute() {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,7 +90,11 @@ class NodeRevisionRevertForm extends ConfirmFormBase implements ContainerInjecti
|
|||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -52,8 +52,10 @@ class NodeTypeDeleteConfirm extends EntityConfirmFormBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/structure/types';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => 'node_overview_types',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,7 +89,7 @@ class NodeTypeDeleteConfirm extends EntityConfirmFormBase {
|
|||
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';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,8 +28,10 @@ class RebuildPermissionsForm extends ConfirmFormBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/reports/status';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => 'system_status',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -65,10 +65,9 @@ class DeleteForm extends ConfirmFormBase implements ContainerInjectionInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\Core\Form\ConfirmFormBase::getCancelPath().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/config/search/path';
|
||||
public function getCancelRoute() {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,7 +76,11 @@ class DeleteForm extends ConfirmFormBase implements ContainerInjectionInterface
|
|||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,8 +21,10 @@ class PictureMappingDeleteForm extends EntityConfirmFormBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/config/media/picturemapping';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => 'picture_mapping_page',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -50,10 +50,12 @@ class ReindexConfirm extends ConfirmFormBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\Core\Form\ConfirmFormBase::getCancelPath().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/config/search/settings';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => 'search_settings',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -39,8 +39,13 @@ class LinkDelete extends ConfirmFormBase {
|
|||
/**
|
||||
* {@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),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -59,8 +59,13 @@ class ShortcutSetDeleteForm extends EntityConfirmFormBase {
|
|||
/**
|
||||
* {@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(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -62,8 +62,10 @@ class DateFormatDeleteForm extends EntityConfirmFormBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/config/regional/date-time';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => 'date_format_list',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -76,8 +76,10 @@ class DateFormatLocalizeResetForm extends ConfirmFormBase implements ContainerIn
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/config/regional/date-time/locale';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => 'date_format_language_overview',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -73,8 +73,10 @@ class ModulesListConfirmForm extends ConfirmFormBase implements ContainerInjecti
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/modules';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => 'system_modules_list',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,7 +109,7 @@ class ModulesListConfirmForm extends ConfirmFormBase implements ContainerInjecti
|
|||
|
||||
// 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->urlGenerator()->generate('system_modules_list', array(), TRUE));
|
||||
}
|
||||
|
||||
$items = array();
|
||||
|
@ -161,7 +163,7 @@ class ModulesListConfirmForm extends ConfirmFormBase implements ContainerInjecti
|
|||
drupal_set_message($this->t('The configuration options have been saved.'));
|
||||
}
|
||||
|
||||
$form_state['redirect'] = $this->getCancelPath();
|
||||
$form_state['redirect'] = 'admin/modules';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -80,8 +80,10 @@ class ModulesUninstallConfirmForm extends ConfirmFormBase implements ContainerIn
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/modules/uninstall';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => 'system_modules_uninstall',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,12 +22,14 @@ class ConfirmFormArrayPathTestForm extends ConfirmFormTestForm {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'path' => 'admin',
|
||||
'route_name' => 'system_admin',
|
||||
'options' => array(
|
||||
'query' => array(
|
||||
'destination' => 'admin/config',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,8 +31,10 @@ class ConfirmFormTestForm extends ConfirmFormBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => 'system_admin',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -60,8 +60,10 @@ class TermDeleteForm extends EntityNGConfirmFormBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/structure/taxonomy';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => 'taxonomy_vocabulary_list',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,8 +32,10 @@ class VocabularyDeleteForm extends EntityConfirmFormBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/structure/taxonomy';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => 'taxonomy_vocabulary_list',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -56,8 +56,13 @@ class VocabularyResetForm extends EntityConfirmFormBase {
|
|||
/**
|
||||
* {@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(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,8 +24,10 @@ class UserRoleDelete extends EntityConfirmFormBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/people/roles';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => 'user_role_list',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -84,8 +84,13 @@ class BreakLockForm extends EntityConfirmFormBase {
|
|||
/**
|
||||
* {@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(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,8 +24,10 @@ class ViewDeleteFormController extends EntityConfirmFormBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelPath() {
|
||||
return 'admin/structure/views';
|
||||
public function getCancelRoute() {
|
||||
return array(
|
||||
'route_name' => 'views_ui.list',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,107 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Form\ConfirmFormHelperTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Form;
|
||||
|
||||
use Drupal\Core\Form\ConfirmFormHelper;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Tests the confirm form helper class.
|
||||
*
|
||||
* @see \Drupal\Core\Form\ConfirmFormHelper
|
||||
*
|
||||
* @group Drupal
|
||||
* @group Form
|
||||
*/
|
||||
class ConfirmFormHelperTest extends UnitTestCase {
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => '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']);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue