Commit 983bfd1e authored by catch's avatar catch

Issue #1841442 by damiankloip, dawehner, tim.plunkett: Fixed Contextual...

Issue #1841442 by damiankloip, dawehner, tim.plunkett: Fixed Contextual filters are broken in the Views UI preview.
parent d3069f0e
<?php
/**
* @file
* Contains \Drupal\views\Tests\UI\PreviewTest.
*/
namespace Drupal\views\Tests\UI;
/**
* Tests the preview form in the UI.
*/
class PreviewTest extends UITestBase {
public static function getInfo() {
return array(
'name' => 'Preview functionality',
'description' => 'Tests the UI preview functionality.',
'group' => 'Views UI',
);
}
/**
* Tests arguments in the preview form.
*/
function testPreviewUI() {
$this->drupalGet('admin/structure/views/view/test_preview/edit');
$this->assertResponse(200);
$this->drupalPost(NULL, $edit = array(), t('Update preview'));
$elements = $this->xpath('//div[@class = "view-content"]/div[contains(@class, views-row)]');
$this->assertEqual(count($elements), 5);
// Filter just the first result.
$this->drupalPost(NULL, $edit = array('view_args' => '1'), t('Update preview'));
$elements = $this->xpath('//div[@class = "view-content"]/div[contains(@class, views-row)]');
$this->assertEqual(count($elements), 1);
// Filter for no results.
$this->drupalPost(NULL, $edit = array('view_args' => '100'), t('Update preview'));
$elements = $this->xpath('//div[@class = "view-content"]/div[contains(@class, views-row)]');
$this->assertEqual(count($elements), 0);
}
}
api_version: '3.0'
base_field: id
base_table: views_test_data
core: 8.x
description: ''
disabled: '0'
display:
default:
display_plugin: default
id: default
display_title: Master
position: ''
display_options:
access:
type: perm
cache:
type: none
query:
type: views_query
exposed_form:
type: basic
pager:
type: some
options:
items_per_page: '10'
offset: '0'
style:
type: default
row:
type: fields
fields:
name:
id: standard
table: views_test_data
field: name
relationship: none
group_type: group
admin_label: ''
label: Name
exclude: '0'
filters: { }
sorts: { }
filter_groups:
operator: AND
groups: { }
title: 'Test preview'
arguments:
id:
id: numeric
table: views_test_data
field: id
relationship: none
group_type: group
admin_label: ''
default_action: ignore
title_enable: '0'
title: ''
human_name: test_preview
module: views
name: test_preview
tag: ''
......@@ -315,9 +315,19 @@ function views_ui_edit_page(ViewUI $view, $display_id = NULL) {
return $build;
}
function views_ui_build_preview(ViewUI $view, $display_id, $render = TRUE) {
/**
* Page callback for rendering the preview form and the preview of the view.
*
* @param \Drupal\views_ui\ViewUI $view
* The view UI object to preview.
* @param string $display_id
* The display ID to preview.
*
* @return array
* The form array of the full preview form.
*/
function views_ui_build_preview(ViewUI $view, $display_id) {
$view->displayID = $display_id;
$view->renderPreview = $render;
return entity_get_form($view, 'preview');
}
......
......@@ -47,7 +47,6 @@ public function form(array $form, array &$form_state, EntityInterface $view) {
'#description' => t('Separate contextual filter values with a "/". For example, %example.', array('%example' => '40/12/10')),
'#id' => 'preview-args',
);
$form['controls']['#action'] = url('admin/structure/views/view/' . $view->get('name') .'/preview/' . $view->displayID);
$args = array();
if (!empty($form_state['values']['view_args'])) {
......@@ -80,6 +79,7 @@ protected function actions(array $form, array &$form_state) {
'#type' => 'submit',
'#value' => t('Update preview'),
'#attributes' => array('class' => array('arguments-preview')),
'#submit' => array(array($this, 'submitPreview')),
'#id' => 'preview-submit',
'#ajax' => array(
'path' => 'admin/structure/views/view/' . $view->get('name') . '/preview/' . $view->displayID . '/ajax',
......@@ -92,4 +92,16 @@ protected function actions(array $form, array &$form_state) {
);
}
/**
* Form submission handler for the Preview button.
*/
public function submitPreview($form, &$form_state) {
// Rebuild the form with a pristine $view object.
$view = $this->getEntity($form_state);
$form_state['build_info']['args'][0] = views_ui_cache_load($view->get('name'));
$view->renderPreview = TRUE;
$form_state['show_preview'] = TRUE;
$form_state['rebuild'] = TRUE;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment