Commit 783bc948 authored by webchick's avatar webchick

Issue #2226871 by tim.plunkett: ConfirmFormInterface::getCancelRoute() should...

Issue #2226871 by tim.plunkett: ConfirmFormInterface::getCancelRoute() should always return Drupal\Core\Url.
parent 4862ed79
......@@ -27,10 +27,6 @@ class ConfirmFormHelper {
*
* @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.
......@@ -45,18 +41,6 @@ public static function buildCancelLink(ConfirmFormInterface $form, Request $requ
}
// Check for a route-based cancel link.
elseif ($route = $form->getCancelRoute()) {
if (!($route instanceof Url)) {
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(),
);
$route = new Url($route['route_name'], $route['route_parameters'], $route['options']);
}
$link = $route->toRenderArray();
}
......
......@@ -23,14 +23,8 @@ public function getQuestion();
/**
* Returns the route to go to if the user cancels the action.
*
* @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.
* @return \Drupal\Core\Url
* A URL object.
*/
public function getCancelRoute();
......
......@@ -8,6 +8,7 @@
namespace Drupal\action\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Url;
/**
* Builds a form to delete an action.
......@@ -32,9 +33,7 @@ public function getConfirmText() {
* {@inheritdoc}
*/
public function getCancelRoute() {
return array(
'route_name' => 'action.admin',
);
return new Url('action.admin');
}
/**
......@@ -46,9 +45,7 @@ public function submit(array $form, array &$form_state) {
watchdog('user', 'Deleted action %aid (%action)', array('%aid' => $this->entity->id(), '%action' => $this->entity->label()));
drupal_set_message($this->t('Action %action was deleted', array('%action' => $this->entity->label())));
$form_state['redirect_route'] = array(
'route_name' => 'action.admin',
);
$form_state['redirect_route'] = $this->getCancelRoute();
}
}
......@@ -8,6 +8,7 @@
namespace Drupal\aggregator\Form;
use Drupal\Core\Entity\ContentEntityConfirmFormBase;
use Drupal\Core\Url;
/**
* Provides a form for deleting a feed.
......@@ -25,9 +26,7 @@ public function getQuestion() {
* {@inheritdoc}
*/
public function getCancelRoute() {
return array(
'route_name' => 'aggregator.admin_overview',
);
return new Url('aggregator.admin_overview');
}
/**
......@@ -45,10 +44,10 @@ public function submit(array $form, array &$form_state) {
watchdog('aggregator', 'Feed %feed deleted.', array('%feed' => $this->entity->label()));
drupal_set_message($this->t('The feed %feed has been deleted.', array('%feed' => $this->entity->label())));
if (arg(0) == 'admin') {
$form_state['redirect_route']['route_name'] = 'aggregator.admin_overview';
$form_state['redirect_route'] = $this->getCancelRoute();
}
else {
$form_state['redirect_route']['route_name'] = 'aggregator.sources';
$form_state['redirect_route'] = new Url('aggregator.sources');
}
}
......
......@@ -8,6 +8,7 @@
namespace Drupal\aggregator\Form;
use Drupal\Core\Entity\ContentEntityConfirmFormBase;
use Drupal\Core\Url;
/**
* Provides a deletion confirmation form for items that belong to a feed.
......@@ -25,9 +26,7 @@ public function getQuestion() {
* {@inheritdoc}
*/
public function getCancelRoute() {
return array(
'route_name' => 'aggregator.admin_overview',
);
return new Url('aggregator.admin_overview');
}
/**
......@@ -43,7 +42,7 @@ public function getConfirmText() {
public function submit(array $form, array &$form_state) {
$this->entity->deleteItems();
$form_state['redirect_route']['route_name'] = 'aggregator.admin_overview';
$form_state['redirect_route'] = $this->getCancelRoute();
}
}
......@@ -9,6 +9,7 @@
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\ban\BanIpManagerInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
......@@ -68,9 +69,7 @@ public function getConfirmText() {
* {@inheritdoc}
*/
public function getCancelRoute() {
return array(
'route_name' => 'ban.admin_page',
);
return new Url('ban.admin_page');
}
/**
......@@ -93,7 +92,7 @@ public function submitForm(array &$form, array &$form_state) {
$this->ipManager->unbanIp($this->banIp);
watchdog('user', 'Deleted %ip', array('%ip' => $this->banIp));
drupal_set_message($this->t('The IP address %ip was deleted.', array('%ip' => $this->banIp)));
$form_state['redirect_route']['route_name'] = 'ban.admin_page';
$form_state['redirect_route'] = $this->getCancelRoute();
}
}
......@@ -8,6 +8,7 @@
namespace Drupal\custom_block\Form;
use Drupal\Core\Entity\ContentEntityConfirmFormBase;
use Drupal\Core\Url;
/**
* Provides a confirmation form for deleting a custom block entity.
......@@ -25,9 +26,7 @@ public function getQuestion() {
* {@inheritdoc}
*/
public function getCancelRoute() {
return array(
'route_name' => 'block.admin_display',
);
return new Url('block.admin_display');
}
/**
......@@ -58,7 +57,7 @@ public function submit(array $form, array &$form_state) {
$this->entity->delete();
drupal_set_message($this->t('Custom block %label has been deleted.', array('%label' => $this->entity->label())));
watchdog('custom_block', 'Custom block %label has been deleted.', array('%label' => $this->entity->label()), WATCHDOG_NOTICE);
$form_state['redirect_route']['route_name'] = 'custom_block.list';
$form_state['redirect_route'] = new Url('custom_block.list');
}
}
......@@ -9,6 +9,7 @@
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -53,9 +54,7 @@ public function getQuestion() {
* {@inheritdoc}
*/
public function getCancelRoute() {
return array(
'route_name' => 'custom_block.type_list',
);
return new Url('custom_block.type_list');
}
/**
......@@ -85,9 +84,9 @@ public function buildForm(array $form, array &$form_state) {
*/
public function submit(array $form, array &$form_state) {
$this->entity->delete();
$form_state['redirect_route']['route_name'] = 'custom_block.type_list';
drupal_set_message(t('Custom block type %label has been deleted.', array('%label' => $this->entity->label())));
watchdog('custom_block', 'Custom block type %label has been deleted.', array('%label' => $this->entity->label()), WATCHDOG_NOTICE);
$form_state['redirect_route'] = $this->getCancelRoute();
}
}
......@@ -8,6 +8,7 @@
namespace Drupal\block\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Url;
/**
* Provides a deletion confirmation form for the block instance deletion form.
......@@ -25,9 +26,7 @@ public function getQuestion() {
* {@inheritdoc}
*/
public function getCancelRoute() {
return array(
'route_name' => 'block.admin_display',
);
return new Url('block.admin_display');
}
/**
......@@ -43,7 +42,7 @@ public function getConfirmText() {
public function submit(array $form, array &$form_state) {
$this->entity->delete();
drupal_set_message($this->t('The block %name has been removed.', array('%name' => $this->entity->label())));
$form_state['redirect_route']['route_name'] = 'block.admin_display';
$form_state['redirect_route'] = $this->getCancelRoute();
}
}
......@@ -9,6 +9,7 @@
use Drupal\book\BookManagerInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Url;
use Drupal\node\NodeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -96,12 +97,7 @@ public function getQuestion() {
* {@inheritdoc}
*/
public function getCancelRoute() {
return array(
'route_name' => 'node.view',
'route_parameters' => array(
'node' => $this->node->id(),
),
);
return $this->node->urlInfo();
}
/**
......@@ -112,12 +108,7 @@ public function submitForm(array &$form, array &$form_state) {
$this->bookManager->deleteFromBook($this->node->id());
drupal_set_message($this->t('The post has been removed from the book.'));
}
$form_state['redirect_route'] = array(
'route_name' => 'node.view',
'route_parameters' => array(
'node' => $this->node->id(),
),
);
$form_state['redirect_route'] = $this->getCancelRoute();
}
}
......@@ -125,7 +125,7 @@ public function overviewBundles() {
if (isset($entity_bundles[$entity_type][$bundle])) {
// Add the current instance.
if ($field_ui_enabled && $route_info = FieldUI::getOverviewRouteInfo($entity_type, $bundle)) {
$row['data']['usage']['data']['#items'][] = $this->l($entity_bundles[$entity_type][$bundle]['label'], $route_info['route_name'], $route_info['route_parameters']);
$row['data']['usage']['data']['#items'][] = \Drupal::linkGenerator()->generateFromUrl($entity_bundles[$entity_type][$bundle]['label'], $route_info);
}
else {
$row['data']['usage']['data']['#items'][] = $entity_bundles[$entity_type][$bundle]['label'];
......
......@@ -11,6 +11,7 @@
use Drupal\Component\Utility\String;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -69,9 +70,7 @@ public function getQuestion() {
* {@inheritdoc}
*/
public function getCancelRoute() {
return array(
'route_name' => 'comment.admin',
);
return new Url('comment.admin');
}
/**
......@@ -126,7 +125,7 @@ public function submitForm(array &$form, array &$form_state) {
watchdog('content', 'Deleted @count comments.', array('@count' => $count));
drupal_set_message(format_plural($count, 'Deleted 1 comment.', 'Deleted @count comments.'));
}
$form_state['redirect_route']['route_name'] = 'comment.admin';
$form_state['redirect_route'] = $this->getCancelRoute();
}
}
......@@ -11,6 +11,7 @@
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -80,9 +81,7 @@ public function getFormID() {
* {@inheritdoc}
*/
public function getCancelRoute() {
return array(
'route_name' => 'config.import_single',
);
return new Url('config.import_single');
}
/**
......
......@@ -8,6 +8,7 @@
use Drupal\Component\Utility\String;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Url;
/**
* Delete confirmation form for config_test entities.
......@@ -32,9 +33,7 @@ public function getConfirmText() {
* {@inheritdoc}
*/
public function getCancelRoute() {
return array(
'route_name' => 'config_test.list_page',
);
return new Url('config_test.list_page');
}
/**
......@@ -43,7 +42,7 @@ public function getCancelRoute() {
public function submit(array $form, array &$form_state) {
$this->entity->delete();
drupal_set_message(String::format('%label configuration has been deleted.', array('%label' => $this->entity->label())));
$form_state['redirect_route']['route_name'] = 'config_test.list_page';
$form_state['redirect_route'] = $this->getCancelRoute();
}
}
......@@ -11,6 +11,7 @@
use Drupal\Core\Cache\Cache;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Url;
use Drupal\language\ConfigurableLanguageManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
......@@ -101,10 +102,7 @@ public function getConfirmText() {
* {@inheritdoc}
*/
public function getCancelRoute() {
return array(
'route_name' => $this->mapper->getOverviewRouteName(),
'route_parameters' => $this->mapper->getOverviewRouteParameters(),
);
return new Url($this->mapper->getOverviewRouteName(), $this->mapper->getOverviewRouteParameters());
}
/**
......@@ -148,10 +146,7 @@ public function submitForm(array &$form, array &$form_state) {
drupal_set_message($this->t('@language translation of %label was deleted', array('%label' => $this->mapper->getTitle(), '@language' => $this->language->name)));
$form_state['redirect_route'] = array(
'route_name' => $this->mapper->getOverviewRoute(),
'route_parameters' => $this->mapper->getOverviewRouteParameters(),
);
$form_state['redirect_route'] = $this->getCancelRoute();
}
}
......@@ -8,6 +8,7 @@
namespace Drupal\contact\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Url;
/**
* Builds the form to delete a contact category.
......@@ -25,9 +26,7 @@ public function getQuestion() {
* {@inheritdoc}
*/
public function getCancelRoute() {
return array(
'route_name' => 'contact.category_list',
);
return new Url('contact.category_list');
}
/**
......@@ -44,7 +43,7 @@ public function submit(array $form, array &$form_state) {
$this->entity->delete();
drupal_set_message(t('Category %label has been deleted.', array('%label' => $this->entity->label())));
watchdog('contact', 'Category %label has been deleted.', array('%label' => $this->entity->label()), WATCHDOG_NOTICE);
$form_state['redirect_route']['route_name'] = 'contact.category_list';
$form_state['redirect_route'] = $this->getCancelRoute();
}
}
......@@ -8,6 +8,7 @@
namespace Drupal\content_translation\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Url;
/**
* Delete translation form for content_translation module.
......@@ -62,12 +63,7 @@ public function getQuestion() {
* {@inheritdoc}
*/
public function getCancelRoute() {
return array(
'route_name' => $this->entity->getEntityType()->getLinkTemplate('drupal:content-translation-overview'),
'route_parameters' => array(
$this->entity->getEntityTypeId() => $this->entity->id(),
),
);
return $this->entity->urlInfo('drupal:content-translation-overview');
}
/**
......
......@@ -8,6 +8,7 @@
namespace Drupal\entity\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Url;
/**
* Provides the delete form for entity display modes.
......@@ -18,9 +19,7 @@ class EntityDisplayModeDeleteForm extends EntityConfirmFormBase {
* {@inheritdoc}
*/
public function getCancelRoute() {
return array(
'route_name' => 'entity.' . $this->entity->getEntityTypeId() . '_list',
);
return new Url('entity.' . $this->entity->getEntityTypeId() . '_list');
}
/**
......@@ -56,7 +55,7 @@ public function submit(array $form, array &$form_state) {
drupal_set_message(t('Deleted the %label @entity-type.', array('%label' => $this->entity->label(), '@entity-type' => $entity_type->getLowercaseLabel())));
$this->entity->delete();
entity_info_cache_clear();
$form_state['redirect_route']['route_name'] = 'entity.' . $this->entity->getEntityTypeId() . '_list';
$form_state['redirect_route'] = $this->getCancelRoute();
}
}
......@@ -137,7 +137,7 @@ public function buildForm(array $form, array &$form_state, $entity_type_id = NUL
);
if (empty($field_definitions) && empty($extra_fields) && $route_info = FieldUI::getOverviewRouteInfo($this->entity_type, $this->bundle)) {
drupal_set_message($this->t('There are no fields yet added. You can add new fields on the <a href="@link">Manage fields</a> page.', array('@link' => $this->url($route_info['route_name'], $route_info['route_parameters'], $route_info['options']))), 'warning');
drupal_set_message($this->t('There are no fields yet added. You can add new fields on the <a href="@link">Manage fields</a> page.', array('@link' => $route_info->toString())), 'warning');
return $form;
}
......
......@@ -111,7 +111,7 @@ public function buildRow(EntityInterface $field) {
$usage = array();
foreach ($field->getBundles() as $bundle) {
if ($route_info = FieldUI::getOverviewRouteInfo($field->entity_type, $bundle)) {
$usage[] = \Drupal::l($this->bundles[$field->entity_type][$bundle]['label'], $route_info['route_name'], $route_info['route_parameters'], $route_info['options']);
$usage[] = \Drupal::linkGenerator()->generateFromUrl($this->bundles[$field->entity_type][$bundle]['label'], $route_info);
}
else {
$usage[] = $this->bundles[$field->entity_type][$bundle]['label'];
......
......@@ -8,6 +8,7 @@
namespace Drupal\field_ui;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Url;
/**
* Static service container wrapper for Field UI.
......@@ -22,25 +23,15 @@ class FieldUI {
* @param string $bundle
* The entity 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.
* - options: (optional) An associative array of additional options. See
* \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute() for
* comprehensive documentation.
* @return \Drupal\Core\Url
* A URL object.
*/
public static function getOverviewRouteInfo($entity_type_id, $bundle) {
$entity_type = \Drupal::entityManager()->getDefinition($entity_type_id);
if ($entity_type->hasLinkTemplate('admin-form')) {
return array(
'route_name' => "field_ui.overview_$entity_type_id",
'route_parameters' => array(
$entity_type->getBundleEntityType() => $bundle,
),
'options' => array(),
);
return new Url("field_ui.overview_$entity_type_id", array(
$entity_type->getBundleEntityType() => $bundle,
));
}
}
......
......@@ -80,7 +80,7 @@ public function submit(array $form, array &$form_state) {
drupal_set_message($this->t('There was a problem removing the %field from the %type content type.', array('%field' => $this->entity->label(), '%type' => $bundle_label)), 'error');
}
$form_state['redirect_route'] = FieldUI::getOverviewRouteInfo($this->entity->entity_type, $this->entity->bundle);
$form_state['redirect_route'] = $this->getCancelRoute();
// Fields are purged on cron. However field module prevents disabling modules
// when field types they provided are used in a field until it is fully
......
......@@ -8,6 +8,7 @@
namespace Drupal\filter\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Url;
/**
* Provides the filter format disable form.
......@@ -25,9 +26,7 @@ public function getQuestion() {
* {@inheritdoc}
*/
public function getCancelRoute() {
return array(
'route_name' => 'filter.admin_overview',
);
return new Url('filter.admin_overview');
}
/**
......@@ -51,7 +50,7 @@ public function submit(array $form, array &$form_state) {
$this->entity->disable()->save();
drupal_set_message(t('Disabled text format %format.', array('%format' => $this->entity->label())));
$form_state['redirect_route']['route_name'] = 'filter.admin_overview';
$form_state['redirect_route'] = $this->getCancelRoute();
}
}
......@@ -8,6 +8,7 @@
namespace Drupal\forum\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Url;
use Drupal\taxonomy\TermInterface;
/**
......@@ -40,9 +41,7 @@ public function getQuestion() {
* {@inheritdoc}
*/
public function getCancelRoute() {
return array(
'route_name' => 'forum.overview',
);
return new Url('forum.overview');
}
/**
......@@ -68,7 +67,7 @@ public function submitForm(array &$form, array &$form_state) {
$this->taxonomyTerm->delete();
drupal_set_message($this->t('The forum %label and all sub-forums have been deleted.', array('%label' => $this->taxonomyTerm->label())));
watchdog('forum', 'forum: deleted %label and all its sub-forums.', array('%label' => $this->taxonomyTerm->label()), WATCHDOG_NOTICE);
$form_state['redirect_route']['route_name'] = 'forum.overview';
$form_state['redirect_route'] = $this->getCancelRoute();
}
}
......@@ -8,6 +8,7 @@
namespace Drupal\image\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Url;
/**
* Creates a form to delete an image style.
......@@ -32,9 +33,7 @@ public function getConfirmText() {
* {@inheritdoc}
*/
public function getCancelRoute() {
return array(
'route_name' => 'image.style_list',
);
return new Url('image.style_list');
}
/**
......@@ -66,7 +65,7 @@ public function submit(array $form, array &$form_state) {
$this->entity->set('replacementID', $form_state['values']['replacement']);
$this->entity->delete();
drupal_set_message($this->t('Style %name was deleted.', array('%name' => $this->entity->label())));
$form_state['redirect_route']['route_name'] = 'image.style_list';
$form_state['redirect_route'] = $this->getCancelRoute();
}
}
......@@ -8,6 +8,7 @@
namespace Drupal\image\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Url;
/**
* Form controller for image style flush.
......@@ -39,9 +40,7 @@ public function getConfirmText() {
* {@inheritdoc}
*/
public function getCancelRoute() {
return array(
'route_name' => 'image.style_list',
);
return new Url('image.style_list');
}
/**
......@@ -50,7 +49,7 @@ public function getCancelRoute() {
public function submit(array $form, array &$form_state) {
$this->entity->flush();
drupal_set_message($this->t('The image style %name has been flushed.', array('%name' => $this->entity->label())));
$form_state['redirect_route']['route_name'] = 'image.style_list';
$form_state['redirect_route'] = $this->getCancelRoute();
}
}
......@@ -9,6 +9,7 @@
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
......@@ -56,9 +57,7 @@ public function getQuestion() {
* {@inheritdoc}
*/
public function getCancelRoute() {
return array(
'route_name' => 'language.admin_overview',
);
return new Url('language.admin_overview');
}
/**
......@@ -115,7 +114,7 @@ public function submit(array $form, array &$form_state) {
drupal_set_message($this->t('The %language (%langcode) language has been removed.', array('%language' => $this->entity->label(), '%langcode' => $this->entity->id())));
}
$form_state['redirect_route']['route_name'] = 'language.admin_overview';
$form_state['redirect_route'] = $this->getCancelRoute();
}
}