diff --git a/core/modules/field/tests/modules/field_test_config/config/install/field.field.entity_test.entity_test.field_test_import.yml b/core/modules/field/tests/modules/field_test_config/config/install/field.field.entity_test.entity_test.field_test_import.yml index b205693efb570341a53c63f1130e9a114924cea7..dd9ec744b472aeb214ec4f452a96bc587c085dc3 100644 --- a/core/modules/field/tests/modules/field_test_config/config/install/field.field.entity_test.entity_test.field_test_import.yml +++ b/core/modules/field/tests/modules/field_test_config/config/install/field.field.entity_test.entity_test.field_test_import.yml @@ -13,3 +13,4 @@ field_type: text dependencies: entity: - field.storage.entity_test.field_test_import +fixed_dependencies: \ No newline at end of file diff --git a/core/modules/views/src/Plugin/views/relationship/GroupwiseMax.php b/core/modules/views/src/Plugin/views/relationship/GroupwiseMax.php index c3f99f89a4205bd43d890f58e793658547e9dd77..636746a13d442a318c1ecf9eb1b781d19c111d99 100644 --- a/core/modules/views/src/Plugin/views/relationship/GroupwiseMax.php +++ b/core/modules/views/src/Plugin/views/relationship/GroupwiseMax.php @@ -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']); } } diff --git a/core/modules/views/src/Tests/Plugin/CacheTest.php b/core/modules/views/src/Tests/Plugin/CacheTest.php index c5bd57d550d7d1a169fa04a91ed2dba79f5f0ec6..396c3a30a61f41c9a6bf1c5010eb8bc24be8164e 100644 --- a/core/modules/views/src/Tests/Plugin/CacheTest.php +++ b/core/modules/views/src/Tests/Plugin/CacheTest.php @@ -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.'); + + } + } diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_groupwise_term_ui.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_groupwise_term_ui.yml new file mode 100644 index 0000000000000000000000000000000000000000..075d87a432c8632d714e9d08cab862a51189b6f4 --- /dev/null +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_groupwise_term_ui.yml @@ -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 diff --git a/core/modules/views_ui/src/Tests/UITestBase.php b/core/modules/views_ui/src/Tests/UITestBase.php index 5d329526a0bf6ce5e611d55247c3fb7546c80ac6..f8cef54bc9e67875c7a0341bc788bbcdf6ef0269 100644 --- a/core/modules/views_ui/src/Tests/UITestBase.php +++ b/core/modules/views_ui/src/Tests/UITestBase.php @@ -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(); diff --git a/core/modules/views_ui/src/Tests/ViewEditTest.php b/core/modules/views_ui/src/Tests/ViewEditTest.php index 62036f1540f879e50f71c2a2b6579689b119ebc2..d9024dd6082688fd29e626219543f2d15f0cebcc 100644 --- a/core/modules/views_ui/src/Tests/ViewEditTest.php +++ b/core/modules/views_ui/src/Tests/ViewEditTest.php @@ -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'); + } + }