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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.