Issue #2239227 by marthinal, andypost | ivanjaros: Fixed Views GroupwiseMax class calls protected properties.
parent
6fa850778a
commit
2c11d0eaef
|
@ -13,3 +13,4 @@ field_type: text
|
||||||
dependencies:
|
dependencies:
|
||||||
entity:
|
entity:
|
||||||
- field.storage.entity_test.field_test_import
|
- field.storage.entity_test.field_test_import
|
||||||
|
fixed_dependencies:
|
|
@ -87,6 +87,7 @@ class GroupwiseMax extends RelationshipPluginBase {
|
||||||
|
|
||||||
// Get the sorts that apply to our base.
|
// Get the sorts that apply to our base.
|
||||||
$sorts = Views::viewsDataHelper()->fetchFields($this->definition['base'], 'sort');
|
$sorts = Views::viewsDataHelper()->fetchFields($this->definition['base'], 'sort');
|
||||||
|
$sort_options = array();
|
||||||
foreach ($sorts as $sort_id => $sort) {
|
foreach ($sorts as $sort_id => $sort) {
|
||||||
$sort_options[$sort_id] = "$sort[group]: $sort[title]";
|
$sort_options[$sort_id] = "$sort[group]: $sort[title]";
|
||||||
}
|
}
|
||||||
|
@ -122,20 +123,14 @@ class GroupwiseMax extends RelationshipPluginBase {
|
||||||
// WIP: This stuff doens't work yet: namespacing issues.
|
// WIP: This stuff doens't work yet: namespacing issues.
|
||||||
// A list of suitable views to pick one as the subview.
|
// A list of suitable views to pick one as the subview.
|
||||||
$views = array('' => '- None -');
|
$views = array('' => '- None -');
|
||||||
$all_views = Views::getAllViews();
|
foreach (Views::getAllViews() as $view) {
|
||||||
foreach ($all_views as $view) {
|
|
||||||
// Only get views that are suitable:
|
// Only get views that are suitable:
|
||||||
// - base must the base that our relationship joins towards
|
// - base must the base that our relationship joins towards
|
||||||
// - must have fields.
|
// - 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?
|
// TODO: check the field is the correct sort?
|
||||||
// or let users hang themselves at this stage and check later?
|
// or let users hang themselves at this stage and check later?
|
||||||
if ($view->type == 'Default') {
|
$views[$view->id()] = $view->id();
|
||||||
$views[t('Default Views')][$view->storage->id()] = $view->storage->id();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$views[t('Existing Views')][$view->storage->id()] = $view->storage->id();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,11 +166,12 @@ class GroupwiseMax extends RelationshipPluginBase {
|
||||||
*/
|
*/
|
||||||
public function submitOptionsForm(&$form, FormStateInterface $form_state) {
|
public function submitOptionsForm(&$form, FormStateInterface $form_state) {
|
||||||
$cid = 'views_relationship_groupwise_max:' . $this->view->storage->id() . ':' . $this->view->current_display . ':' . $this->options['id'];
|
$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.
|
* 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
|
* 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
|
* generate the subquery when the options are saved, rather than when the view
|
||||||
* is run. This saves considerable time.
|
* is run. This saves considerable time.
|
||||||
|
@ -184,7 +180,8 @@ class GroupwiseMax extends RelationshipPluginBase {
|
||||||
* An array of options:
|
* An array of options:
|
||||||
* - subquery_sort: the id of a views sort.
|
* - subquery_sort: the id of a views sort.
|
||||||
* - subquery_order: either ASC or DESC.
|
* - subquery_order: either ASC or DESC.
|
||||||
* @return
|
*
|
||||||
|
* @return string
|
||||||
* The subquery SQL string, ready for use in the main query.
|
* The subquery SQL string, ready for use in the main query.
|
||||||
*/
|
*/
|
||||||
protected function leftQuery($options) {
|
protected function leftQuery($options) {
|
||||||
|
@ -358,13 +355,13 @@ class GroupwiseMax extends RelationshipPluginBase {
|
||||||
else {
|
else {
|
||||||
// Get the stored subquery SQL string.
|
// Get the stored subquery SQL string.
|
||||||
$cid = 'views_relationship_groupwise_max:' . $this->view->storage->id() . ':' . $this->view->current_display . ':' . $this->options['id'];
|
$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)) {
|
if (isset($cache->data)) {
|
||||||
$def['left_query'] = $cache->data;
|
$def['left_query'] = $cache->data;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$def['left_query'] = $this->leftQuery($this->options);
|
$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
|
* @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() {
|
protected function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
@ -175,4 +182,19 @@ class CacheTest extends PluginTestBase {
|
||||||
$this->assertTrue(empty($output['#attached']['js']), 'The cached view does not have attached JS.');
|
$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.');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
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
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $modules = array('node', 'views_ui', 'block');
|
public static $modules = array('node', 'views_ui', 'block', 'taxonomy');
|
||||||
|
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
|
@ -23,7 +23,7 @@ class ViewEditTest extends UITestBase {
|
||||||
*
|
*
|
||||||
* @var array
|
* @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.
|
* Tests the delete link on a views UI.
|
||||||
|
@ -153,4 +153,16 @@ class ViewEditTest extends UITestBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue