Overrides Drupal\Core\Entity\EntityFormController::submit().
Overrides EntityFormController::submit
public function submit(array $form, array &$form_state) {
parent::submit($form, $form_state);
$view = $this->entity;
// Go through and remove displayed scheduled for removal.
$displays = $view
->get('display');
foreach ($displays as $id => $display) {
if (!empty($display['deleted'])) {
$view
->get('executable')->displayHandlers
->remove($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
->set($new_id, $view
->get('executable')->displayHandlers
->get($id));
$view
->get('executable')->displayHandlers
->get($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
->id() . '/edit/' . $new_id;
}
}
$view
->set('display', $displays);
// @todo: Revisit this when http://drupal.org/node/1668866 is in.
$query = $this->request->query;
$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
->id());
$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
->get($id)
->getOption('path')) {
$destination = $view
->get('executable')->displayHandlers
->get($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
->label(),
)));
// Remove this view from cache so we can edit it properly.
$this->tempStore
->delete($view
->id());
}