diff --git a/core/modules/views_ui/js/ajax.js b/core/modules/views_ui/js/ajax.js index a591f3981e3757a7ae72fbf056da06fc50c3f9ba..87c7a1b4bb7f27b5b42e12c83e206dca4f13a7fb 100644 --- a/core/modules/views_ui/js/ajax.js +++ b/core/modules/views_ui/js/ajax.js @@ -156,8 +156,8 @@ return true; } - element_settings.wrapper = 'views-live-preview'; - element_settings.method = 'html'; + element_settings.wrapper = 'views-preview-wrapper'; + element_settings.method = 'replaceWith'; var base = $(this).attr('id'); Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings); }); @@ -179,8 +179,8 @@ return true; } - element_settings.wrapper = 'views-live-preview'; - element_settings.method = 'html'; + element_settings.wrapper = 'views-preview-wrapper'; + element_settings.method = 'replaceWith'; element_settings.event = 'click'; var base = $(this).attr('id'); diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Tests/PreviewTest.php b/core/modules/views_ui/lib/Drupal/views_ui/Tests/PreviewTest.php index 5523518f04de0cc554fad8ba4463770793f4680d..6ed06409e7334ad21408ffd420e11f089d4c689c 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/Tests/PreviewTest.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/Tests/PreviewTest.php @@ -114,6 +114,39 @@ public function testPreviewWithPagersUI() { $this->assertClass($elements[4], 'pager-last', "Element for last page has .pager-last class."); $this->assertTrue($elements[4]->a, "Link to last page found."); + // Navigate to next page. + $elements = $this->xpath('//li[contains(@class, :class)]/a', array(':class' => 'pager-next')); + $this->clickPreviewLinkAJAX($elements[0]['href'], 5); + + // Test that the pager is present and rendered. + $elements = $this->xpath('//ul[@class = "pager"]/li'); + $this->assertTrue(!empty($elements), 'Full pager found.'); + + // Verify elements and links to pages. + // We expect to find 7 elements: links to '<< first' and '< previous' + // pages, link to page 1, current page == 2, link to page 3 and links + // to 'next >' and 'last >>' pages. + $this->assertClass($elements[0], 'pager-first', "Element for next page has .pager-first class."); + $this->assertTrue($elements[0]->a, "Link to first page found."); + + $this->assertClass($elements[1], 'pager-previous', "Element for previous page has .pager-previous class."); + $this->assertTrue($elements[1]->a, "Link to previous page found."); + + $this->assertClass($elements[2], 'pager-item', "Element for page 1 has .pager-item class."); + $this->assertTrue($elements[2]->a, "Link to page 1 found."); + + $this->assertClass($elements[3], 'pager-current', 'Element for current page has .pager-current class.'); + $this->assertFalse(isset($elements[3]->a), 'Element for current page has no link.'); + + $this->assertClass($elements[4], 'pager-item', "Element for page 3 has .pager-item class."); + $this->assertTrue($elements[4]->a, "Link to page 3 found."); + + $this->assertClass($elements[5], 'pager-next', "Element for next page has .pager-next class."); + $this->assertTrue($elements[5]->a, "Link to next page found."); + + $this->assertClass($elements[6], 'pager-last', "Element for last page has .pager-last class."); + $this->assertTrue($elements[6]->a, "Link to last page found."); + // Test Mini Pager. $this->getPreviewAJAX('test_mini_pager', 'default', 3); @@ -132,6 +165,26 @@ public function testPreviewWithPagersUI() { $this->assertClass($elements[2], 'pager-next', "Element for next page has .pager-next class."); $this->assertTrue($elements[2]->a, "Link to next page found."); + + // Navigate to next page. + $elements = $this->xpath('//li[contains(@class, :class)]/a', array(':class' => 'pager-next')); + $this->clickPreviewLinkAJAX($elements[0]['href'], 3); + + // Test that the pager is present and rendered. + $elements = $this->xpath('//ul[@class = "pager"]/li'); + $this->assertTrue(!empty($elements), 'Mini pager found.'); + + // Verify elements and links to pages. + // We expect to find 3 elements: previous page with a link, current + // page with no link, and next page with a link. + $this->assertClass($elements[0], 'pager-previous', 'Element for previous page has .pager-previous class.'); + $this->assertTrue($elements[0]->a, "Link to previous page found."); + + $this->assertClass($elements[1], 'pager-current', 'Element for current page has .pager-current class.'); + $this->assertFalse(isset($elements[1]->a), 'Element for current page has no link.'); + + $this->assertClass($elements[2], 'pager-next', "Element for next page has .pager-next class."); + $this->assertTrue($elements[2]->a, "Link to next page found."); } /** @@ -147,7 +200,36 @@ public function testPreviewWithPagersUI() { protected function getPreviewAJAX($view_name, $panel_id, $row_count) { $this->drupalGet('admin/structure/views/view/' . $view_name . '/preview/' . $panel_id); $result = $this->drupalPostAJAX(NULL, array(), array('op' => t('Update preview'))); + $this->assertPreviewAJAX($result, $row_count); + } + + /** + * Mimic clicking on a preview link. + * + * @param string $url + * The url to navigate to. + * @param int $row_count + * The expected number of rows in the preview. + */ + protected function clickPreviewLinkAJAX($url, $row_count) { + $ajax_settings = array( + 'url' => $url, + 'wrapper' => 'views-preview-wrapper', + 'method' => 'replaceWith', + ); + $result = $this->drupalPostAJAX(NULL, array(), NULL, NULL, array(), array(), NULL, $ajax_settings); + $this->assertPreviewAJAX($result, $row_count); + } + /** + * Assert that the AJAX response contains expected data. + * + * @param array $result + * An array of AJAX commands. + * @param int $row_count + * The expected number of rows in the preview. + */ + protected function assertPreviewAJAX($result, $row_count) { // Has AJAX callback replied with an insert command? If so, we can // assume that the page content was updated with AJAX returned data. $result_commands = array(); diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewPreviewFormController.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewPreviewFormController.php index 4ac5b8cf504b64a6fd99cbe8ad8ab924304d0411..fb292faf15246ef6d01176d641e710aacf521d12 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewPreviewFormController.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewPreviewFormController.php @@ -89,7 +89,7 @@ public function form(array $form, array &$form_state) { $args = explode('/', $form_state['values']['view_args']); } - if (!empty($form_state['show_preview'])) { + if (!empty($form_state['show_preview']) || !empty($form_state['input']['js'])) { $form['preview'] = array( '#weight' => 110, '#theme_wrappers' => array('container'), @@ -122,7 +122,7 @@ protected function actions(array $form, array &$form_state) { 'wrapper' => 'views-preview-wrapper', 'event' => 'click', 'progress' => array('type' => 'throbber'), - 'method' => 'replace', + 'method' => 'replaceWith', ), ), ); diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php index 78bbecac80c42080d275eaf1effcb5b175e7fc1c..7bae9560bd8acbfdf8f731e9eb049aa58900284a 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php @@ -541,17 +541,17 @@ public function renderPreview($display_id, $args = array()) { $this->executable->live_preview = TRUE; $this->views_ui_context = TRUE; - // AJAX happens via $_POST but everything expects exposed data to + // AJAX happens via HTTP POST but everything expects exposed data to // be in GET. Copy stuff but remove ajax-framework specific keys. // If we're clicking on links in a preview, though, we could actually - // still have some in $_GET, so we use $_REQUEST to ensure we get it all. - $exposed_input = \Drupal::request()->request->all(); + // have some input in the query parameters, so we merge request() and + // query() to ensure we get it all. + $exposed_input = array_merge(\Drupal::request()->request->all(), \Drupal::request()->query->all()); foreach (array('view_name', 'view_display_id', 'view_args', 'view_path', 'view_dom_id', 'pager_element', 'view_base_path', 'ajax_html_ids', 'ajax_page_state', 'form_id', 'form_build_id', 'form_token') as $key) { if (isset($exposed_input[$key])) { unset($exposed_input[$key]); } } - $this->executable->setExposedInput($exposed_input); if (!$this->executable->setDisplay($display_id)) {