Commit 2c11d0ea authored by alexpott's avatar alexpott

Issue #2239227 by marthinal, andypost | ivanjaros: Fixed Views GroupwiseMax...

Issue #2239227 by marthinal, andypost | ivanjaros: Fixed Views GroupwiseMax class calls protected properties.
parent 6fa85077
......@@ -13,3 +13,4 @@ field_type: text
dependencies:
entity:
- field.storage.entity_test.field_test_import
fixed_dependencies:
\ No newline at end of file
......@@ -87,6 +87,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
// Get the sorts that apply to our base.
$sorts = Views::viewsDataHelper()->fetchFields($this->definition['base'], 'sort');
$sort_options = array();
foreach ($sorts as $sort_id => $sort) {
$sort_options[$sort_id] = "$sort[group]: $sort[title]";
}
......@@ -122,20 +123,14 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
// WIP: This stuff doens't work yet: namespacing issues.
// A list of suitable views to pick one as the subview.
$views = array('' => '- None -');
$all_views = Views::getAllViews();
foreach ($all_views as $view) {
foreach (Views::getAllViews() as $view) {
// Only get views that are suitable:
// - base must the base that our relationship joins towards
// - must have fields.
if ($view->base_table == $this->definition['base'] && !empty($view->display['default']['display_options']['fields'])) {
if ($view->get('base_table') == $this->definition['base'] && !empty($view->getDisplay('default')['display_options']['fields'])) {
// TODO: check the field is the correct sort?
// or let users hang themselves at this stage and check later?
if ($view->type == 'Default') {
$views[t('Default Views')][$view->storage->id()] = $view->storage->id();
}
else {
$views[t('Existing Views')][$view->storage->id()] = $view->storage->id();
}
$views[$view->id()] = $view->id();
}
}
......@@ -171,11 +166,12 @@ protected function getTemporaryView() {
*/
public function submitOptionsForm(&$form, FormStateInterface $form_state) {
$cid = 'views_relationship_groupwise_max:' . $this->view->storage->id() . ':' . $this->view->current_display . ':' . $this->options['id'];
\Drupal::cache('views_results')->delete($cid);
\Drupal::cache('data')->delete($cid);
}
/**
* Generate a subquery given the user options, as set in the options.
*
* These are passed in rather than picked up from the object because we
* generate the subquery when the options are saved, rather than when the view
* is run. This saves considerable time.
......@@ -184,7 +180,8 @@ public function submitOptionsForm(&$form, FormStateInterface $form_state) {
* An array of options:
* - subquery_sort: the id of a views sort.
* - subquery_order: either ASC or DESC.
* @return
*
* @return string
* The subquery SQL string, ready for use in the main query.
*/
protected function leftQuery($options) {
......@@ -358,13 +355,13 @@ public function query() {
else {
// Get the stored subquery SQL string.
$cid = 'views_relationship_groupwise_max:' . $this->view->storage->id() . ':' . $this->view->current_display . ':' . $this->options['id'];
$cache = \Drupal::cache('views_results')->get($cid);
$cache = \Drupal::cache('data')->get($cid);
if (isset($cache->data)) {
$def['left_query'] = $cache->data;
}
else {
$def['left_query'] = $this->leftQuery($this->options);
\Drupal::cache('views_results')->set($cid, $def['left_query']);
\Drupal::cache('data')->set($cid, $def['left_query']);
}
}
......
......@@ -23,7 +23,14 @@ class CacheTest extends PluginTestBase {
*
* @var array
*/
public static $testViews = array('test_view', 'test_cache');
public static $testViews = array('test_view', 'test_cache', 'test_groupwise_term_ui');
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('taxonomy');
protected function setUp() {
parent::setUp();
......@@ -175,4 +182,19 @@ function testHeaderStorage() {
$this->assertTrue(empty($output['#attached']['js']), 'The cached view does not have attached JS.');
}
/**
* Tests that Subqueries are cached as expected.
*/
public function testSubqueryStringCache() {
// Execute the view.
$view = Views::getView('test_groupwise_term_ui');
$view->setDisplay();
$this->executeView($view);
// Request for the cache.
$cid = 'views_relationship_groupwise_max:test_groupwise_term_ui:default:tid_representative';
$cache = \Drupal::cache('data')->get($cid);
$this->assertEqual($cid, $cache->cid, 'Subquery String cached as expected.');
}
}
base_field: tid
base_table: taxonomy_term_data
core: 8.0-dev
description: ''
status: true
display:
default:
display_options:
access:
type: perm
cache:
type: none
exposed_form:
type: basic
fields:
name:
field: name
id: name
table: taxonomy_term_field_data
plugin_id: taxonomy
provider: taxonomy
nid:
field: nid
id: nid
relationship: tid_representative
table: node
plugin_id: node
provider: node
pager:
options:
items_per_page: 10
type: full
query:
type: views_query
relationships:
tid_representative:
admin_label: ''
field: tid_representative
group_type: group
id: tid_representative
label: 'Representative node'
relationship: none
required: false
subquery_namespace: ''
subquery_order: DESC
subquery_regenerate: false
subquery_sort: node.nid
subquery_view: ''
table: taxonomy_term_data
plugin_id: groupwise_max
provider: views
row:
type: fields
sorts:
tid:
field: tid
id: tid
order: DESC
table: taxonomy_term_data
plugin_id: standard
provider: views
style:
type: default
title: test_groupwise
display_plugin: default
display_title: Master
id: default
position: 0
label: test_groupwise
langcode: und
module: views
id: test_groupwise_term_ui
tag: default
......@@ -33,7 +33,7 @@ abstract class UITestBase extends ViewTestBase {
*
* @var array
*/
public static $modules = array('node', 'views_ui', 'block');
public static $modules = array('node', 'views_ui', 'block', 'taxonomy');
protected function setUp() {
parent::setUp();
......
......@@ -23,7 +23,7 @@ class ViewEditTest extends UITestBase {
*
* @var array
*/
public static $testViews = array('test_view', 'test_display');
public static $testViews = array('test_view', 'test_display', 'test_groupwise_term_ui');
/**
* Tests the delete link on a views UI.
......@@ -153,4 +153,16 @@ public function testPluginProviders() {
}
}
/**
* Tests Representative Node for a Taxonomy Term.
*/
public function testRelationRepresentativeNode() {
// Populate and submit the form.
$edit["name[taxonomy_term_data.tid_representative]"] = TRUE;
$this->drupalPostForm('admin/structure/views/nojs/add-handler/test_groupwise_term_ui/default/relationship', $edit, 'Add and configure relationships');
// Apply changes.
$edit = array();
$this->drupalPostForm('admin/structure/views/nojs/handler/test_groupwise_term_ui/default/relationship/tid_representative', $edit, 'Apply');
}
}
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