Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function submit(array $form, FormStateInterface $form_state)
 {
     $original = parent::submit($form, $form_state);
     $this->entity = $original->createDuplicate();
     $this->entity->set('id', $form_state['values']['id']);
     $this->entity->save();
     // Redirect the user to the view admin form.
     $form_state->setRedirectUrl($this->entity->urlInfo('edit-form'));
     return $this->entity;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function submit(array $form, array &$form_state)
 {
     parent::submit($form, $form_state);
     $view = $this->entity;
     $executable = $view->getExecutable();
     // Go through and remove displayed scheduled for removal.
     $displays = $view->get('display');
     foreach ($displays as $id => $display) {
         if (!empty($display['deleted'])) {
             $executable->displayHandlers->remove($id);
             unset($displays[$id]);
         }
     }
     // Rename display ids if needed.
     foreach ($executable->displayHandlers as $id => $display) {
         if (!empty($display->display['new_id'])) {
             $new_id = $display->display['new_id'];
             $display->display['id'] = $new_id;
             unset($display->display['new_id']);
             $executable->displayHandlers->set($new_id, $display);
             $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_route'] = array('route_name' => 'views_ui.edit_display', 'route_parameters' => array('view' => $view->id(), 'display_id' => $new_id));
         }
     }
     $view->set('display', $displays);
     // @todo: Revisit this when http://drupal.org/node/1668866 is in.
     $query = $this->requestStack->getCurrentRequest()->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::getView($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->getExecutable()->displayHandlers->get($id)->getOption('path')) {
                 $destination = $view->getExecutable()->displayHandlers->get($id)->getOption('path');
                 $query->remove('destination');
             }
         }
         $form_state['redirect'] = $destination;
     }
     $view->save();
     drupal_set_message($this->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());
 }