diff --git a/core/modules/views/lib/Drupal/views/Tests/UI/DisplayTest.php b/core/modules/views/lib/Drupal/views/Tests/UI/DisplayTest.php index 4e7f32d..aa1b696 100644 --- a/core/modules/views/lib/Drupal/views/Tests/UI/DisplayTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/UI/DisplayTest.php @@ -127,8 +127,8 @@ public function testReorderDisplay() { // Put the block display in front of the page display. $edit = array( - 'page_1[weight]' => 2, - 'block_1[weight]' => 1 + 'displays[page_1][weight]' => 2, + 'displays[block_1][weight]' => 1 ); $this->drupalPost(NULL, $edit, t('Apply')); $this->drupalPost(NULL, array(), t('Save')); diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ReorderDisplays.php b/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ReorderDisplays.php index a14210c..e12bc7f 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ReorderDisplays.php +++ b/core/modules/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('Reorder displays'); + $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'])) { @@ -108,26 +143,29 @@ public function submitForm(array &$form, array &$form_state) { // Sort the order array asort($order); - // Fixing up positions + // Remove the default display from ordering. + unset($order['default']); + // Increment up positions. $position = 1; foreach (array_keys($order) as $display) { - $order[$display] = $position++; + $order[$display] = $position; + $position++; } // Setting up position and removing deleted displays $displays = $view->get('display'); - foreach ($displays as $display_id => $display) { + foreach ($displays as $display_id => &$display) { // Don't touch the default !!! if ($display_id === 'default') { - $displays[$display_id]['position'] = 0; + $display['position'] = 0; continue; } if (isset($order[$display_id])) { - $displays[$display_id]['position'] = $order[$display_id]; + $display['position'] = $order[$display_id]; } else { - $displays[$display_id]['deleted'] = TRUE; + $display['deleted'] = TRUE; } } $view->set('display', $displays); diff --git a/core/modules/views_ui/views_ui.module b/core/modules/views_ui/views_ui.module index 0ae5c3a..a27f1bf 100644 --- a/core/modules/views_ui/views_ui.module +++ b/core/modules/views_ui/views_ui.module @@ -135,12 +135,6 @@ function views_ui_theme() { 'file' => 'views_ui.theme.inc', ), - // Reordering displays. - 'views_ui_reorder_displays_form' => array( - 'render element' => 'form', - 'file' => 'views_ui.theme.inc', - ), - // On behalf of a plugin 'views_ui_style_plugin_table' => array( 'render element' => 'form', diff --git a/core/modules/views_ui/views_ui.theme.inc b/core/modules/views_ui/views_ui.theme.inc index 841f15c..47ef8bf 100644 --- a/core/modules/views_ui/views_ui.theme.inc +++ b/core/modules/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) {