You are here

function views_ui_edit_view_form_submit in Views (for Drupal 7) 8.3

Same name and namespace in other branches
  1. 6.3 includes/admin.inc \views_ui_edit_view_form_submit()
  2. 6.2 includes/admin.inc \views_ui_edit_view_form_submit()
  3. 7.3 includes/admin.inc \views_ui_edit_view_form_submit()

Submit handler for the edit view form.

1 string reference to 'views_ui_edit_view_form_submit'
ViewUI::buildEditForm in views_ui/lib/Drupal/views_ui/ViewUI.php
Form builder callback for editing a View.

File

views_ui/admin.inc, line 599
Provides the Views' administrative interface.

Code

function views_ui_edit_view_form_submit($form, &$form_state) {

  // Go through and remove displayed scheduled for removal.
  foreach ($form_state['view']->storage->display as $id => $display) {
    if (!empty($display['deleted'])) {
      unset($form_state['view']->displayHandlers[$id]);
      unset($form_state['view']->storage->display[$id]);
    }
  }

  // Rename display ids if needed.
  foreach ($form_state['view']->displayHandlers as $id => $display) {
    if (!empty($display->display['new_id'])) {
      $new_id = $display->display['new_id'];
      $form_state['view']->displayHandlers[$new_id] = $form_state['view']->displayHandlers[$id];
      $form_state['view']->displayHandlers[$new_id]->display['id'] = $new_id;
      $form_state['view']->storage->display[$new_id] = $form_state['view']->storage->display[$id];
      unset($form_state['view']->storage->display[$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/' . $form_state['view']->storage->name . '/edit/' . $new_id;
    }
  }

  // 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($form_state['view']->storage->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 != $form_state['view']->displayHandlers[$id]
        ->getOption('path')) {
        $destination = $form_state['view']->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;
  }
  $form_state['view']
    ->save();
  drupal_set_message(t('The view %name has been saved.', array(
    '%name' => $form_state['view']->storage
      ->getHumanName(),
  )));

  // Remove this view from cache so we can edit it properly.
  drupal_container()
    ->get('user.tempstore')
    ->get('views')
    ->delete($form_state['view']->storage->name);
}