Commit 627a719a authored by alexpott's avatar alexpott

Issue #2189661 by tim.plunkett: Replace $form_state['redirect_route'] with setRedirect().

parent a98ed74b
......@@ -602,7 +602,15 @@ public function setResponse(Response $response) {
/**
* {@inheritdoc}
*/
public function setRedirect(Url $url) {
public function setRedirect($route_name, array $route_parameters = array(), array $options = array()) {
$url = new Url($route_name, $route_parameters, $options);
return $this->setRedirectUrl($url);
}
/**
* {@inheritdoc}
*/
public function setRedirectUrl(Url $url) {
$this->set('redirect_route', $url);
return $this;
}
......@@ -627,20 +635,12 @@ public function getRedirect() {
// Check for a route-based redirection.
if ($redirect_route = $this->get('redirect_route')) {
// @todo Remove once all redirects are converted to \Drupal\Core\Url. See
// https://www.drupal.org/node/2189661.
if (!($redirect_route instanceof Url)) {
$redirect_route += array(
'route_parameters' => array(),
'options' => array(),
);
$redirect_route = new Url($redirect_route['route_name'], $redirect_route['route_parameters'], $redirect_route['options']);
}
$redirect_route->setAbsolute();
return $redirect_route;
}
// @todo Remove once all redirects are converted away from paths in
// https://www.drupal.org/node/2315807.
return $this->get('redirect');
}
......
......@@ -89,6 +89,23 @@ public function setIfNotExists($property, $value);
*/
public function setResponse(Response $response);
/**
* Sets the redirect for the form.
*
* @param string $route_name
* The name of the route
* @param array $route_parameters
* (optional) An associative array of parameter names and values.
* @param array $options
* (optional) An associative array of additional options. See
* \Drupal\Core\Url for the available keys.
*
* @return $this
*
* @see \Drupal\Core\Form\FormSubmitterInterface::redirectForm()
*/
public function setRedirect($route_name, array $route_parameters = array(), array $options = array());
/**
* Sets the redirect URL for the form.
*
......@@ -99,7 +116,7 @@ public function setResponse(Response $response);
*
* @see \Drupal\Core\Form\FormSubmitterInterface::redirectForm()
*/
public function setRedirect(Url $url);
public function setRedirectUrl(Url $url);
/**
* Gets the value to use for redirecting after the form has been executed.
......
......@@ -150,9 +150,7 @@ public function save(array $form, FormStateInterface $form_state) {
$this->entity->save();
drupal_set_message($this->t('The action has been successfully saved.'));
$form_state['redirect_route'] = array(
'route_name' => 'action.admin',
);
$form_state->setRedirect('action.admin');
}
}
......@@ -90,9 +90,9 @@ public function buildForm(array $form, FormStateInterface $form_state) {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
if ($form_state['values']['action']) {
$form_state['redirect_route'] = array(
'route_name' => 'action.admin_add',
'route_parameters' => array('action_id' => $form_state['values']['action']),
$form_state->setRedirect(
'action.admin_add',
array('action_id' => $form_state['values']['action'])
);
}
}
......
......@@ -46,7 +46,7 @@ public function submit(array $form, FormStateInterface $form_state) {
$this->logger('user')->notice('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'] = $this->getCancelUrl();
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
......@@ -67,7 +67,7 @@ public function save(array $form, FormStateInterface $form_state) {
$feed->save();
if ($insert) {
drupal_set_message($this->t('The feed %feed has been updated.', array('%feed' => $feed->label())));
$form_state['redirect_route'] = $feed->urlInfo('canonical');
$form_state->setRedirectUrl($feed->urlInfo('canonical'));
}
else {
$this->logger('aggregator')->notice('Feed %feed added.', array('%feed' => $feed->label(), 'link' => l($this->t('View'), 'admin/config/services/aggregator')));
......
......@@ -44,7 +44,7 @@ public function submit(array $form, FormStateInterface $form_state) {
$this->entity->delete();
$this->logger('aggregator')->notice('Feed %feed deleted.', array('%feed' => $this->entity->label()));
drupal_set_message($this->t('The feed %feed has been deleted.', array('%feed' => $this->entity->label())));
$form_state['redirect_route'] = new Url('aggregator.sources');
$form_state->setRedirect('aggregator.sources');
}
}
......@@ -43,7 +43,7 @@ public function getConfirmText() {
public function submit(array $form, FormStateInterface $form_state) {
$this->entity->deleteItems();
$form_state['redirect_route'] = $this->getCancelUrl();
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
......@@ -173,7 +173,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$new_feed->save();
}
$form_state['redirect_route']['route_name'] = 'aggregator.admin_overview';
$form_state->setRedirect('aggregator.admin_overview');
}
/**
......
......@@ -124,7 +124,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$ip = trim($form_state['values']['ip']);
$this->ipManager->banIp($ip);
drupal_set_message($this->t('The IP address %ip has been banned.', array('%ip' => $ip)));
$form_state['redirect_route']['route_name'] = 'ban.admin_page';
$form_state->setRedirect('ban.admin_page');
}
}
......@@ -93,7 +93,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$this->ipManager->unbanIp($this->banIp);
$this->logger('user')->notice('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'] = $this->getCancelUrl();
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
......@@ -181,14 +181,12 @@ public function submit(array $form, FormStateInterface $form_state) {
$entity->save();
drupal_set_message($this->t('The block configuration has been saved.'));
$form_state['redirect_route'] = array(
'route_name' => 'block.admin_display_theme',
'route_parameters' => array(
$form_state->setRedirect(
'block.admin_display_theme',
array(
'theme' => $form_state['values']['theme'],
),
'options' => array(
'query' => array('block-placement' => drupal_html_class($this->entity->id()))
),
array('query' => array('block-placement' => drupal_html_class($this->entity->id())))
);
}
......
......@@ -43,7 +43,7 @@ public function getConfirmText() {
public function submit(array $form, FormStateInterface $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'] = $this->getCancelUrl();
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
......@@ -215,16 +215,16 @@ public function save(array $form, FormStateInterface $form_state) {
if (!$theme = $block->getTheme()) {
$theme = $this->config('system.theme')->get('default');
}
$form_state['redirect_route'] = array(
'route_name' => 'block.admin_add',
'route_parameters' => array(
$form_state->setRedirect(
'block.admin_add',
array(
'plugin_id' => 'block_content:' . $block->uuid(),
'theme' => $theme,
),
)
);
}
else {
$form_state['redirect_route']['route_name'] = 'block_content.list';
$form_state->setRedirect('block_content.list');
}
}
else {
......
......@@ -103,7 +103,7 @@ public function save(array $form, FormStateInterface $form_state) {
$logger->notice('Custom block type %label has been added.', array('%label' => $block_type->label(), 'link' => $edit_link));
}
$form_state['redirect_route']['route_name'] = 'block_content.type_list';
$form_state->setRedirect('block_content.type_list');
}
}
......@@ -58,7 +58,7 @@ public function submit(array $form, FormStateInterface $form_state) {
$this->entity->delete();
drupal_set_message($this->t('Custom block %label has been deleted.', array('%label' => $this->entity->label())));
$this->logger('block_content')->notice('Custom block %label has been deleted.', array('%label' => $this->entity->label()));
$form_state['redirect_route'] = new Url('block_content.list');
$form_state->setRedirect('block_content.list');
}
}
......@@ -87,7 +87,7 @@ public function submit(array $form, FormStateInterface $form_state) {
$this->entity->delete();
drupal_set_message(t('Custom block type %label has been deleted.', array('%label' => $this->entity->label())));
$this->logger('block_content')->notice('Custom block type %label has been deleted.', array('%label' => $this->entity->label()));
$form_state['redirect_route'] = $this->getCancelUrl();
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
......@@ -102,11 +102,9 @@ protected function actions(array $form, FormStateInterface $form_state) {
* @see book_remove_button_submit()
*/
public function submit(array $form, FormStateInterface $form_state) {
$form_state['redirect_route'] = array(
'route_name' => 'node.view',
'route_parameters' => array(
'node' => $this->entity->id(),
),
$form_state->setRedirect(
'node.view',
array('node' => $this->entity->id())
);
$book_link = $form_state['values']['book'];
if (!$book_link['bid']) {
......@@ -119,7 +117,7 @@ public function submit(array $form, FormStateInterface $form_state) {
if (isset($this->entity->book['parent_mismatch']) && $this->entity->book['parent_mismatch']) {
// This will usually only happen when JS is disabled.
drupal_set_message($this->t('The post has been added to the selected book. You may now position it relative to other pages.'));
$form_state['redirect_route'] = $this->entity->urlInfo('book-outline-form');
$form_state->setRedirectUrl($this->entity->urlInfo('book-outline-form'));
}
else {
drupal_set_message($this->t('The book outline has been updated.'));
......@@ -134,7 +132,7 @@ public function submit(array $form, FormStateInterface $form_state) {
* {@inheritdoc}
*/
public function delete(array $form, FormStateInterface $form_state) {
$form_state['redirect_route'] = $this->entity->urlInfo('book-remove-form');
$form_state->setRedirectUrl($this->entity->urlInfo('book-remove-form'));
}
}
......@@ -109,7 +109,7 @@ public function submitForm(array &$form, FormStateInterface $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'] = $this->getCancelUrl();
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
......@@ -403,6 +403,6 @@ public function save(array $form, FormStateInterface $form_state) {
drupal_set_message($this->t('Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', array('%subject' => $comment->getSubject())), 'error');
// Redirect the user to the entity they are commenting on.
}
$form_state['redirect_route'] = $uri;
$form_state->setRedirectUrl($uri);
}
}
......@@ -147,7 +147,7 @@ public function save(array $form, FormStateInterface $form_state) {
$this->logger->notice('Comment type %label has been added.', array('%label' => $comment_type->label(), 'link' => $edit_link));
}
$form_state['redirect_route']['route_name'] = 'comment.type_list';
$form_state->setRedirect('comment.type_list');
}
}
......@@ -281,9 +281,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
}
}
drupal_set_message($this->t('The update has been performed.'));
$form_state['redirect_route'] = array(
'route_name' => 'comment.admin',
);
$form_state->setRedirect('comment.admin');
}
}
......@@ -143,7 +143,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
*/
public function submit(array $form, FormStateInterface $form_state) {
$this->entity->delete();
$form_state['redirect_route']['route_name'] = 'comment.type_list';
$form_state->setRedirect('comment.type_list');
drupal_set_message($this->t('Comment type %label has been deleted.', array('%label' => $this->entity->label())));
$this->logger->notice('comment type %label has been deleted.', array('%label' => $this->entity->label()));
}
......
......@@ -108,7 +108,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
if (!$comment_counter) {
drupal_set_message($this->t('There do not appear to be any comments to delete, or your selected comment was deleted by another administrator.'));
$form_state['redirect_route']['route_name'] = 'comment.admin';
$form_state->setRedirect('comment.admin');
}
return parent::buildForm($form, $form_state);
......@@ -124,7 +124,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$this->logger('content')->notice('Deleted @count comments.', array('@count' => $count));
drupal_set_message(format_plural($count, 'Deleted 1 comment.', 'Deleted @count comments.'));
}
$form_state['redirect_route'] = $this->getCancelUrl();
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
......@@ -53,7 +53,7 @@ public function submit(array $form, FormStateInterface $form_state) {
drupal_set_message($this->t('The comment and all its replies have been deleted.'));
$this->logger('content')->notice('Deleted comment @cid and its replies.', array('@cid' => $this->entity->id()));
$form_state['redirect_route'] = $this->getCancelUrl();
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
......@@ -40,7 +40,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state['redirect_route']['route_name'] = 'config.export_download';
$form_state->setRedirect('config.export_download');
}
}
......@@ -98,7 +98,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
}
$archiver->extractList($files, config_get_config_directory(CONFIG_STAGING_DIRECTORY));
drupal_set_message($this->t('Your configuration files were successfully uploaded, ready for import.'));
$form_state['redirect_route']['route_name'] = 'config.sync';
$form_state->setRedirect('config.sync');
}
catch (\Exception $e) {
drupal_set_message($this->t('Could not extract the contents of the tar file. The error message is <em>@message</em>', array('@message' => $e->getMessage())), 'error');
......
......@@ -81,7 +81,7 @@ public function save(array $form, FormStateInterface $form_state) {
drupal_set_message(format_string('%label configuration has been created.', array('%label' => $entity->label())));
}
$form_state['redirect_route']['route_name'] = 'config_test.list_page';
$form_state->setRedirect('config_test.list_page');
}
}
......@@ -43,7 +43,7 @@ public function getCancelUrl() {
public function submit(array $form, FormStateInterface $form_state) {
$this->entity->delete();
drupal_set_message(String::format('%label configuration has been deleted.', array('%label' => $this->entity->label())));
$form_state['redirect_route'] = $this->getCancelUrl();
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
......@@ -147,7 +147,7 @@ public function submitForm(array &$form, FormStateInterface $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'] = $this->getCancelUrl();
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
......@@ -242,9 +242,9 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
}
$config_factory->setOverrideState($old_state);
$form_state['redirect_route'] = array(
'route_name' => $this->mapper->getOverviewRoute(),
'route_parameters' => $this->mapper->getOverviewRouteParameters(),
$form_state->setRedirect(
$this->mapper->getOverviewRoute(),
$this->mapper->getOverviewRouteParameters()
);
}
......
......@@ -120,7 +120,7 @@ public function save(array $form, FormStateInterface $form_state) {
->save();
}
$form_state['redirect_route']['route_name'] = 'contact.category_list';
$form_state->setRedirect('contact.category_list');
}
}
......@@ -44,7 +44,7 @@ public function submit(array $form, FormStateInterface $form_state) {
$this->entity->delete();
drupal_set_message($this->t('Category %label has been deleted.', array('%label' => $this->entity->label())));
$this->logger('contact')->notice('Category %label has been deleted.', array('%label' => $this->entity->label()));
$form_state['redirect_route'] = $this->getCancelUrl();
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
......@@ -258,10 +258,10 @@ public function save(array $form, FormStateInterface $form_state) {
// To avoid false error messages caused by flood control, redirect away from
// the contact form; either to the contacted user account or the front page.
if ($message->isPersonal() && $user->hasPermission('access user profiles')) {
$form_state['redirect_route'] = $message->getPersonalRecipient()->urlInfo();
$form_state->setRedirectUrl($message->getPersonalRecipient()->urlInfo());
}
else {
$form_state['redirect_route']['route_name'] = '<front>';
$form_state->setRedirect('<front>');
}
// Save the message. In core this is a no-op but should contrib wish to
// implement message storage, this will make the task of swapping in a real
......
......@@ -83,7 +83,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
\Drupal::service('path.alias_storage')->delete($conditions);
}
$form_state['redirect_route'] = $this->getCancelUrl();
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
......@@ -72,7 +72,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$_SESSION['dblog_overview_filter'] = array();
$this->connection->delete('watchdog')->execute();
drupal_set_message($this->t('Database log cleared.'));
$form_state['redirect_route'] = $this->getCancelUrl();
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
......@@ -10,7 +10,6 @@
use Drupal\Core\Database\Connection;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -71,7 +70,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state['redirect_route'] = new Url('dblog.confirm');
$form_state->setRedirect('dblog.confirm');
}
}
......@@ -56,7 +56,7 @@ public function submit(array $form, FormStateInterface $form_state) {
drupal_set_message(t('Deleted the %label @entity-type.', array('%label' => $this->entity->label(), '@entity-type' => $entity_type->getLowercaseLabel())));
$this->entity->delete();
\Drupal::entityManager()->clearCachedFieldDefinitions();
$form_state['redirect_route'] = $this->getCancelUrl();
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
......@@ -125,7 +125,7 @@ public function save(array $form, FormStateInterface $form_state) {
drupal_set_message(t('Saved the %label @entity-type.', array('%label' => $this->entity->label(), '@entity-type' => $this->entityType->getLowercaseLabel())));
$this->entity->save();
\Drupal::entityManager()->clearCachedFieldDefinitions();
$form_state['redirect_route']['route_name'] = 'entity.' . $this->entity->getEntityTypeId() . '_list';
$form_state->setRedirect('entity.' . $this->entity->getEntityTypeId() . '_list');
}
}
......@@ -201,7 +201,7 @@ function field_ui_entity_operation(EntityInterface $entity) {
*/
function field_ui_form_node_type_form_submit($form, FormStateInterface $form_state) {
if ($form_state['triggering_element']['#parents'][0] === 'save_continue' && $route_info = FieldUI::getOverviewRouteInfo('node', $form_state['values']['type'])) {
$form_state['redirect_route'] = $route_info;
$form_state->setRedirectUrl($route_info);
}
}
......
......@@ -478,7 +478,13 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
if ($destinations) {
$destination = drupal_get_destination();
$destinations[] = $destination['destination'];
$form_state['redirect_route'] = FieldUI::getNextDestination($destinations, $form_state);
$next_destination = FieldUI::getNextDestination($destinations, $form_state);
if (isset($next_destination['route_name'])) {
$form_state->setRedirect($next_destination['route_name'], $next_destination['route_parameters'], $next_destination['options']);
}
else {
$form_state['redirect'] = $next_destination;
}
}
elseif (!$error) {
drupal_set_message($this->t('Your settings have been saved.'));
......
......@@ -48,6 +48,9 @@ public static function getNextDestination(array $destinations) {
$next_destination = array_shift($destinations);
if (is_array($next_destination)) {
$next_destination['options']['query']['destinations'] = $destinations;
$next_destination += array(
'route_parameters' => array(),
);
}
else {
$options = UrlHelper::parse($next_destination);
......
......@@ -81,7 +81,7 @@ public function submit(array $form, FormStateInterface $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'] = $this->getCancelUrl();
$form_state->setRedirectUrl($this->getCancelUrl());
// 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
......
......@@ -196,14 +196,14 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
if (($destinations = $request->query->get('destinations')) && $next_destination = FieldUI::getNextDestination($destinations)) {
$request->query->remove('destinations');
if (isset($next_destination['route_name'])) {
$form_state['redirect_route'] = $next_destination;
$form_state->setRedirect($next_destination['route_name'], $next_destination['route_parameters'], $next_destination['options']);
}
else {
$form_state['redirect'] = $next_destination;
}
}
else {
$form_state['redirect_route'] = FieldUI::getOverviewRouteInfo($this->instance->entity_type, $this->instance->bundle);
$form_state->setRedirectUrl(FieldUI::getOverviewRouteInfo($this->instance->entity_type, $this->instance->bundle));
}
}
......@@ -218,15 +218,13 @@ public function delete(array &$form, FormStateInterface $form_state) {
$request->query->remove('destination');
}
$entity_type = $this->entityManager->getDefinition($this->instance->entity_type);
$form_state['redirect_route'] = array(
'route_name' => 'field_ui.delete_' . $this->instance->entity_type,
'route_parameters' => array(
$form_state->setRedirect(
'field_ui.delete_' . $this->instance->entity_type,
array(
$entity_type->getBundleEntityType() => $this->instance->bundle,
'field_instance_config' => $this->instance->id(),
),
'options' => array(
'query' => $destination,
),
array('query' => $destination)
);
}
......
......@@ -199,14 +199,14 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
if (($destinations = $request->query->get('destinations')) && $next_destination = FieldUI::getNextDestination($destinations)) {
$request->query->remove('destinations');
if (isset($next_destination['route_name'])) {
$form_state['redirect_route'] = $next_destination;
$form_state->setRedirect($next_destination['route_name'], $next_destination['route_parameters'], $next_destination['options']);
}
else {
$form_state['redirect'] = $next_destination;
}
}
else {
$form_state['redirect_route'] = FieldUI::getOverviewRouteInfo($this->instance->entity_type, $this->instance->bundle);
$form_state->setRedirectUrl(FieldUI::getOverviewRouteInfo($this->instance->entity_type, $this->instance->bundle));
}
}
catch (\Exception $e) {
......
......@@ -258,7 +258,7 @@ public function submit(array $form, FormStateInterface $form_state) {
}
}
$form_state['redirect_route']['route_name'] = 'filter.admin_overview';
$form_state->setRedirect('filter.admin_overview');
return $this->entity;
}
......
......@@ -51,7 +51,7 @@ public function submit(array $form, FormStateInterface $form_state) {
$this->entity->disable()->save();
drupal_set_message($this->t('Disabled text format %format.', array('%format' => $this->entity->label())));