ViewEditForm::form

public ViewEditForm::form(array $form, FormStateInterface $form_state)

Gets the actual form array to be built.

Overrides EntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

core/modules/views_ui/src/ViewEditForm.php, line 87

Class

ViewEditForm
Form controller for the Views edit form.

Namespace

Drupal\views_ui

Code

public function form(array $form, FormStateInterface $form_state) {
  $view = $this->entity;
  $display_id = $this->displayID;
  // Do not allow the form to be cached, because $form_state->get('view') can become
  // stale between page requests.
  // See views_ui_ajax_get_form() for how this affects #ajax.
  // @todo To remove this and allow the form to be cacheable:
  //   - Change $form_state->get('view') to $form_state->getTemporary()['view'].
  //   - Add a #process function to initialize $form_state->getTemporary()['view']
  //     on cached form submissions.
  //   - Use \Drupal\Core\Form\FormStateInterface::loadInclude().
  $form_state->disableCache();

  if ($display_id) {
    if (!$view->getExecutable()->setDisplay($display_id)) {
      $form['#markup'] = $this->t('Invalid display id @display', array('@display' => $display_id));
      return $form;
    }
  }

  $form['#tree'] = TRUE;

  $form['#attached']['library'][] = 'core/jquery.ui.tabs';
  $form['#attached']['library'][] = 'core/jquery.ui.dialog';
  $form['#attached']['library'][] = 'core/drupal.states';
  $form['#attached']['library'][] = 'core/drupal.tabledrag';
  $form['#attached']['library'][] = 'views_ui/views_ui.admin';
  $form['#attached']['library'][] = 'views_ui/admin.styling';

  $form += array(
    '#prefix' => '',
    '#suffix' => '',
  );

  $view_status = $view->status() ? 'enabled' : 'disabled';
  $form['#prefix'] .= '<div class="views-edit-view views-admin ' . $view_status . ' clearfix">';
  $form['#suffix'] = '</div>' . $form['#suffix'];

  $form['#attributes']['class'] = array('form-edit');

  if ($view->isLocked()) {
    $username = array(
      '#theme' => 'username',
      '#account' => $this->entityManager->getStorage('user')->load($view->lock->owner),
    );
    $lock_message_substitutions = array(
      '@user' => drupal_render($username),
      '@age' => $this->dateFormatter->formatTimeDiffSince($view->lock->updated),
      ':url' => $view->url('break-lock-form'),
    );
    $form['locked'] = array(
      '#type' => 'container',
      '#attributes' => array('class' => array('view-locked', 'messages', 'messages--warning')),
      '#children' => $this->t('This view is being edited by user @user, and is therefore locked from editing by others. This lock is @age old. Click here to <a href=":url">break this lock</a>.', $lock_message_substitutions),
      '#weight' => -10,
    );
  }
  else {
    $form['changed'] = array(
      '#type' => 'container',
      '#attributes' => array('class' => array('view-changed', 'messages', 'messages--warning')),
      '#children' => $this->t('You have unsaved changes.'),
      '#weight' => -10,
    );
    if (empty($view->changed)) {
      $form['changed']['#attributes']['class'][] = 'js-hide';
    }
  }

  $form['displays'] = array(
    '#prefix' => '<h1 class="unit-title clearfix">' . $this->t('Displays') . '</h1>',
    '#type' => 'container',
    '#attributes' => array(
      'class' => array(
        'views-displays',
      ),
    ),
  );


  $form['displays']['top'] = $this->renderDisplayTop($view);

  // The rest requires a display to be selected.
  if ($display_id) {
    $form_state->set('display_id', $display_id);

    // The part of the page where editing will take place.
    $form['displays']['settings'] = array(
      '#type' => 'container',
      '#id' => 'edit-display-settings',
      '#attributes' => array(
        'class' => array('edit-display-settings'),
      ),
    );

    // Add a text that the display is disabled.
    if ($view->getExecutable()->displayHandlers->has($display_id)) {
      if (!$view->getExecutable()->displayHandlers->get($display_id)->isEnabled()) {
        $form['displays']['settings']['disabled']['#markup'] = $this->t('This display is disabled.');
      }
    }

    // Add the edit display content
    $tab_content = $this->getDisplayTab($view);
    $tab_content['#theme_wrappers'] = array('container');
    $tab_content['#attributes'] = array('class' => array('views-display-tab'));
    $tab_content['#id'] = 'views-tab-' . $display_id;
    // Mark deleted displays as such.
    $display = $view->get('display');
    if (!empty($display[$display_id]['deleted'])) {
      $tab_content['#attributes']['class'][] = 'views-display-deleted';
    }
    // Mark disabled displays as such.

    if ($view->getExecutable()->displayHandlers->has($display_id) && !$view->getExecutable()->displayHandlers->get($display_id)->isEnabled()) {
      $tab_content['#attributes']['class'][] = 'views-display-disabled';
    }
    $form['displays']['settings']['settings_content'] = array(
      '#type' => 'container',
      'tab_content' => $tab_content,
    );
  }

  return $form;
}
doc_Drupal
2016-10-29 09:53:58
Comments
Leave a Comment

Please login to continue.