public function ViewUI::buildDisplaysReorderForm

Form constructor callback to reorder displays on a view

File

drupal/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php, line 358
Definition of Drupal\views_ui\ViewUI.

Class

ViewUI
Stores UI related temporary settings.

Namespace

Drupal\views_ui

Code

public function buildDisplaysReorderForm($form, &$form_state) {
  $display_id = $form_state['display_id'];
  $form['view'] = array(
    '#type' => 'value',
    '#value' => $this,
  );
  $form['#tree'] = TRUE;
  $count = count($this
    ->get('display'));
  $displays = $this
    ->get('display');
  uasort($displays, array(
    'static',
    'sortPosition',
  ));
  $this
    ->set('display', $displays);
  foreach ($displays as $display) {
    $form[$display['id']] = array(
      'title' => array(
        '#markup' => $display['display_title'],
      ),
      'weight' => array(
        '#type' => 'weight',
        '#value' => $display['position'],
        '#delta' => $count,
        '#title' => t('Weight for @display', array(
          '@display' => $display['display_title'],
        )),
        '#title_display' => 'invisible',
      ),
      '#tree' => TRUE,
      '#display' => $display,
      'removed' => array(
        '#type' => 'checkbox',
        '#id' => 'display-removed-' . $display['id'],
        '#attributes' => array(
          'class' => array(
            'views-remove-checkbox',
          ),
        ),
        '#default_value' => isset($display['deleted']),
      ),
    );
    if (isset($display['deleted']) && $display['deleted']) {
      $form[$display['id']]['deleted'] = array(
        '#type' => 'value',
        '#value' => TRUE,
      );
    }
    if ($display['id'] === 'default') {
      unset($form[$display['id']]['weight']);
      unset($form[$display['id']]['removed']);
    }
  }
  $form['#title'] = t('Displays Reorder');
  $form['#section'] = 'reorder';

  // Add javascript settings that will be added via $.extend for tabledragging
  $form['#js']['tableDrag']['reorder-displays']['weight'][0] = array(
    'target' => 'weight',
    'source' => NULL,
    'relationship' => 'sibling',
    'action' => 'order',
    'hidden' => TRUE,
    'limit' => 0,
  );
  $form['#action'] = url('admin/structure/views/nojs/reorder-displays/' . $this
    ->get('name') . '/' . $display_id);
  $this
    ->getStandardButtons($form, $form_state, 'views_ui_reorder_displays_form');
  $form['buttons']['submit']['#submit'] = array(
    array(
      $this,
      'submitDisplaysReorderForm',
    ),
  );
  return $form;
}