Commit 627a719a authored by alexpott's avatar alexpott
Browse files

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);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment