Overrides Drupal\Core\Entity\EntityFormController::submit().
Overrides EntityFormController::submit
public function submit(array $form, array &$form_state) {
parent::submit($form, $form_state);
$view = $this
->getEntity($form_state);
// Go through and remove displayed scheduled for removal.
$displays = $view
->get('display');
foreach ($displays as $id => $display) {
if (!empty($display['deleted'])) {
unset($view
->get('executable')->displayHandlers[$id]);
unset($displays[$id]);
}
}
// Rename display ids if needed.
foreach ($view
->get('executable')->displayHandlers as $id => $display) {
if (!empty($display->display['new_id'])) {
$new_id = $display->display['new_id'];
$view
->get('executable')->displayHandlers[$new_id] = $view
->get('executable')->displayHandlers[$id];
$view
->get('executable')->displayHandlers[$new_id]->display['id'] = $new_id;
$displays[$new_id] = $displays[$id];
unset($displays[$id]);
// Redirect the user to the renamed display to be sure that the page itself exists and doesn't throw errors.
$form_state['redirect'] = 'admin/structure/views/view/' . $view
->get('name') . '/edit/' . $new_id;
}
}
$view
->set('display', $displays);
// Direct the user to the right url, if the path of the display has changed.
$query = drupal_container()
->get('request')->query;
// @todo: Revisit this when http://drupal.org/node/1668866 is in.
$destination = $query
->get('destination');
if (!empty($destination)) {
// Find out the first display which has a changed path and redirect to this url.
$old_view = views_get_view($view
->get('name'));
$old_view
->initDisplay();
foreach ($old_view->displayHandlers as $id => $display) {
// Only check for displays with a path.
$old_path = $display
->getOption('path');
if (empty($old_path)) {
continue;
}
if ($display
->getPluginId() == 'page' && $old_path == $destination && $old_path != $view
->get('executable')->displayHandlers[$id]
->getOption('path')) {
$destination = $view
->get('executable')->displayHandlers[$id]
->getOption('path');
$query
->remove('destination');
// @todo For whatever reason drupal_goto is still using $_GET.
// @see http://drupal.org/node/1668866
unset($_GET['destination']);
}
}
$form_state['redirect'] = $destination;
}
$view
->save();
drupal_set_message(t('The view %name has been saved.', array(
'%name' => $view
->getHumanName(),
)));
// Remove this view from cache so we can edit it properly.
drupal_container()
->get('user.tempstore')
->get('views')
->delete($view
->get('name'));
}