diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/Form/Ajax/ReorderDisplays.php b/core/modules/views/views_ui/lib/Drupal/views_ui/Form/Ajax/ReorderDisplays.php
index a14210c..d9d86c1 100644
--- a/core/modules/views/views_ui/lib/Drupal/views_ui/Form/Ajax/ReorderDisplays.php
+++ b/core/modules/views/views_ui/lib/Drupal/views_ui/Form/Ajax/ReorderDisplays.php
@@ -35,57 +35,90 @@ public function buildForm(array $form, array &$form_state) {
$view = $form_state['view'];
$display_id = $form_state['display_id'];
- $form['view'] = array('#type' => 'value', '#value' => $view);
+ $form['#title'] = t('Displays Reorder');
+ $form['#section'] = 'reorder';
+ $form['#action'] = url('admin/structure/views/nojs/reorder-displays/' . $view->id() . '/' . $display_id);
+ $form['view'] = array(
+ '#type' => 'value',
+ '#value' => $view
+ );
- $form['#tree'] = TRUE;
+ $displays = $view->get('display');
+ $count = count($displays);
- $count = count($view->get('display'));
+ // Sort the displays.
+ uasort($displays, function ($display1, $display2) {
+ if ($display1['position'] != $display2['position']) {
+ return $display1['position'] < $display2['position'] ? -1 : 1;
+ }
+ return 0;
+ });
+
+ $form['displays'] = array(
+ '#type' => 'table',
+ '#id' => 'reorder-displays',
+ '#header' => array(t('Display'), t('Weight'), t('Remove')),
+ '#empty' => t('No displays available.'),
+ '#tabledrag' => array(
+ array('order', 'sibling', 'weight'),
+ ),
+ '#tree' => TRUE,
+ '#prefix' => '
',
+ '#suffix' => '
',
+ );
- $displays = $view->get('display');
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,
+ $id = $display['id'];
+
+ $form['displays'][$id] = array(
'#display' => $display,
- 'removed' => array(
- '#type' => 'checkbox',
- '#id' => 'display-removed-' . $display['id'],
- '#attributes' => array('class' => array('views-remove-checkbox')),
- '#default_value' => isset($display['deleted']),
+ '#attributes' => array(
+ 'id' => 'display-row-' . $id,
+ 'class' => array(),
),
+ '#weight' => $display['position'],
);
- 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']);
+ // Only make row draggable if it's not the default display.
+ if ($id !== 'default') {
+ $form['displays'][$id]['#attributes']['class'][] = 'draggable';
}
- }
+ $form['displays'][$id]['title'] = array(
+ '#markup' => $display['display_title'],
+ );
- $form['#title'] = t('Displays Reorder');
- $form['#section'] = 'reorder';
+ $form['displays'][$id]['weight'] = array(
+ '#type' => 'weight',
+ '#value' => $display['position'],
+ '#delta' => $count,
+ '#title' => t('Weight for @display', array('@display' => $display['display_title'])),
+ '#title_display' => 'invisible',
+ '#attributes' => array(
+ 'class' => array('weight'),
+ ),
+ );
- // 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['displays'][$id]['removed'] = array(
+ '#type' => 'checkbox',
+ '#id' => 'display-removed-' . $id,
+ '#attributes' => array(
+ 'class' => array('views-remove-checkbox')
+ ),
+ '#default_value' => !empty($display['deleted']),
+ '#suffix' => l('' . t('Remove') . '', 'javascript:void()', array('attributes' => array('id' => 'display-remove-link-' . $id, 'class' => array('views-button-remove display-remove-link'), 'alt' => t('Remove this display'), 'title' => t('Remove this display')), 'html' => TRUE)),
+ '#access' => ($id !== 'default'),
+ );
- $form['#action'] = url('admin/structure/views/nojs/reorder-displays/' . $view->id() . '/' . $display_id);
+ if (!empty($display['deleted'])) {
+ $form['displays'][$id]['deleted'] = array(
+ '#type' => 'value',
+ '#value' => TRUE,
+ );
+ $form['displays'][$id]['#attributes']['style'] = 'display: none;';
+ }
+
+ }
$view->getStandardButtons($form, $form_state, 'views_ui_reorder_displays_form');
@@ -97,7 +130,9 @@ public function buildForm(array $form, array &$form_state) {
*/
public function submitForm(array &$form, array &$form_state) {
$view = $form_state['view'];
- foreach ($form_state['input'] as $display => $info) {
+ $order = array();
+
+ foreach ($form_state['input']['displays'] as $display => $info) {
// add each value that is a field with a weight to our list, but only if
// it has had its 'removed' checkbox checked.
if (is_array($info) && isset($info['weight']) && empty($info['removed'])) {
diff --git a/core/modules/views/views_ui/views_ui.theme.inc b/core/modules/views/views_ui/views_ui.theme.inc
index 841f15c..47ef8bf 100644
--- a/core/modules/views/views_ui/views_ui.theme.inc
+++ b/core/modules/views/views_ui/views_ui.theme.inc
@@ -185,64 +185,6 @@ function theme_views_ui_build_group_filter_form($variables) {
}
/**
- * Turn the reorder form into a proper table
- */
-function theme_views_ui_reorder_displays_form($vars) {
- $form = $vars['form'];
- $rows = array();
- foreach (element_children($form) as $key) {
- if (isset($form[$key]['#display'])) {
- $display = &$form[$key];
-
- $row = array();
- $row[] = drupal_render($display['title']);
- $form[$key]['weight']['#attributes']['class'] = array('weight');
- $row[] = drupal_render($form[$key]['weight']);
- if (isset($display['removed'])) {
- $row[] = drupal_render($form[$key]['removed']) .
- l('' . t('Remove') . '',
- 'javascript:void()',
- array(
- 'attributes' => array(
- 'id' => 'display-remove-link-' . $key,
- 'class' => array('views-button-remove display-remove-link'),
- 'alt' => t('Remove this display'),
- 'title' => t('Remove this display')),
- 'html' => TRUE));
- }
- else {
- $row[] = '';
- }
- $class = array();
- $styles = array();
- if (isset($form[$key]['weight']['#type'])) {
- $class[] = 'draggable';
- }
- if (isset($form[$key]['deleted']['#value']) && $form[$key]['deleted']['#value']) {
- $styles[] = 'display: none;';
- }
- $rows[] = array('data' => $row, 'class' => $class, 'id' => 'display-row-' . $key, 'style' => $styles);
- }
- }
-
- $header = array(t('Display'), t('Weight'), t('Remove'));
- $output = '';
- drupal_add_tabledrag('reorder-displays', 'order', 'sibling', 'weight');
-
- $output = drupal_render($form['override']);
- $output .= '';
- $output .= theme('table',
- array('header' => $header,
- 'rows' => $rows,
- 'attributes' => array('id' => 'reorder-displays'),
- ));
- $output .= '
';
- $output .= drupal_render_children($form);
-
- return $output;
-}
-
-/**
* Turn the rearrange form into a proper table
*/
function theme_views_ui_rearrange_filter_form(&$vars) {