Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     parent::form($form, $form_state);
     $form['#title'] = $this->t('Duplicate of @label', array('@label' => $this->entity->label()));
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('View name'), '#required' => TRUE, '#size' => 32, '#maxlength' => 255, '#default_value' => $this->t('Duplicate of @label', array('@label' => $this->entity->label())));
     $form['id'] = array('#type' => 'machine_name', '#maxlength' => 128, '#machine_name' => array('exists' => '\\Drupal\\views\\Views::getView', 'source' => array('label')), '#default_value' => '', '#description' => $this->t('A unique machine-readable name for this View. It must only contain lowercase letters, numbers, and underscores.'));
     return $form;
 }
 /**
  * {@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;
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateForm($form, $form_state);
     $view = $this->entity;
     if ($view->isLocked()) {
         $form_state->setErrorByName('', $this->t('Changes cannot be made to a locked view.'));
     }
     foreach ($view->getExecutable()->validate() as $display_errors) {
         foreach ($display_errors as $error) {
             $form_state->setErrorByName('', $error);
         }
     }
 }
Exemple #4
0
 /**
  * {@inheritdoc}
  */
 protected function actions(array $form, FormStateInterface $form_state)
 {
     $actions = parent::actions($form, $form_state);
     $actions['submit']['#value'] = $this->t('Save and edit');
     // Remove EntityFormController::save() form the submission handlers.
     $actions['submit']['#submit'] = array(array($this, 'submitForm'));
     $actions['cancel'] = array('#type' => 'submit', '#value' => $this->t('Cancel'), '#submit' => array('::cancel'), '#limit_validation_errors' => array());
     return $actions;
 }
 /**
  * {@inheritdoc}
  */
 public function render()
 {
     $entities = $this->load();
     $list['#type'] = 'container';
     $list['#attributes']['id'] = 'views-entity-list';
     $list['#attached']['css'] = ViewFormBase::getAdminCSS();
     $list['#attached']['library'][] = 'core/drupal.ajax';
     $list['#attached']['library'][] = 'views_ui/views_ui.listing';
     $form['filters'] = array('#type' => 'container', '#attributes' => array('class' => array('table-filter', 'js-show')));
     $list['filters']['text'] = array('#type' => 'search', '#title' => $this->t('Search'), '#size' => 30, '#placeholder' => $this->t('Enter view name'), '#attributes' => array('class' => array('views-filter-text'), 'data-table' => '.views-listing-table', 'autocomplete' => 'off', 'title' => $this->t('Enter a part of the view name or description to filter by.')));
     $list['enabled']['heading']['#markup'] = '<h2>' . $this->t('Enabled') . '</h2>';
     $list['disabled']['heading']['#markup'] = '<h2>' . $this->t('Disabled') . '</h2>';
     foreach (array('enabled', 'disabled') as $status) {
         $list[$status]['#type'] = 'container';
         $list[$status]['#attributes'] = array('class' => array('views-list-section', $status));
         $list[$status]['table'] = array('#type' => 'table', '#attributes' => array('class' => array('views-listing-table')), '#header' => $this->buildHeader(), '#rows' => array());
         foreach ($entities[$status] as $entity) {
             $list[$status]['table']['#rows'][$entity->id()] = $this->buildRow($entity);
         }
     }
     // @todo Use a placeholder for the entity label if this is abstracted to
     // other entity types.
     $list['enabled']['table']['#empty'] = $this->t('There are no enabled views.');
     $list['disabled']['table']['#empty'] = $this->t('There are no disabled views.');
     return $list;
 }
Exemple #6
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());
 }
Exemple #7
0
 /**
  * {@inheritdoc}
  */
 protected function actions(array $form, FormStateInterface $form_state)
 {
     $actions = parent::actions($form, $form_state);
     $actions['submit']['#value'] = $this->t('Save and edit');
     $actions['cancel'] = array('#type' => 'submit', '#value' => $this->t('Cancel'), '#submit' => array(array($this, 'cancel')), '#limit_validation_errors' => array());
     return $actions;
 }