Commit bc8686e5 authored by alexpott's avatar alexpott

Issue #1867642 by dawehner, damiankloip: Expose forum tables to views.

parent bea3588b
<?php
/**
* @file
* Provide views data and handlers for forum.module.
*
* @ingroup views_module_handlers
*/
/**
* Implements hook_views_data().
*/
function forum_views_data() {
$data['forum_index']['table']['group'] = t('Forum');
$data['forum_index']['table']['base'] = array(
'field' => 'nid',
'title' => t('Forum content'),
'access query tag' => 'node_access',
);
$data['forum_index']['nid'] = array(
'title' => t('Nid'),
'help' => t('The content ID of the forum index entry.'),
'field' => array(
'id' => 'numeric',
),
'filter' => array(
'id' => 'numeric',
),
'argument' => array(
'id' => 'numeric',
),
'sort' => array(
'id' => 'standard',
),
'relationship' => array(
'base' => 'node',
'base field' => 'nid',
'label' => t('Node'),
),
);
$data['forum_index']['title'] = array(
'title' => t('Title'),
'help' => t('The content title.'),
'field' => array(
'id' => 'standard',
'link_to_node default' => TRUE,
),
'sort' => array(
'id' => 'standard',
),
'filter' => array(
'id' => 'string',
),
'argument' => array(
'id' => 'string',
),
);
$data['forum_index']['tid'] = array(
'title' => t('Has taxonomy term ID'),
'help' => t('Display content if it has the selected taxonomy terms.'),
'argument' => array(
'id' => 'taxonomy_index_tid',
'name table' => 'taxonomy_term_data',
'name field' => 'name',
'empty field name' => t('Uncategorized'),
'numeric' => TRUE,
'skip base' => 'taxonomy_term_data',
),
'field' => array(
'id' => 'numeric',
),
'filter' => array(
'title' => t('Has taxonomy term'),
'id' => 'taxonomy_index_tid',
'hierarchy table' => 'taxonomy_term_hierarchy',
'numeric' => TRUE,
'skip base' => 'taxonomy_term_data',
'allow empty' => TRUE,
),
'relationship' => array(
'base' => 'taxonomy_term',
'base field' => 'tid',
'label' => t('Term'),
),
);
$data['forum_index']['created'] = array(
'title' => t('Post date'),
'help' => t('The date the content was posted.'),
'field' => array(
'id' => 'date',
),
'sort' => array(
'id' => 'date'
),
'filter' => array(
'id' => 'date',
),
);
$data['forum_index']['sticky'] = array(
'title' => t('Sticky'),
'help' => t('Whether or not the content is sticky.'),
'field' => array(
'id' => 'boolean',
'click sortable' => TRUE,
'output formats' => array(
'sticky' => array(t('Sticky'), t('Not sticky')),
),
),
'filter' => array(
'id' => 'boolean',
'label' => t('Sticky'),
'type' => 'yes-no',
),
'sort' => array(
'id' => 'standard',
'help' => t('Whether or not the content is sticky. To list sticky content first, set this to descending.'),
),
);
$data['forum_index']['last_comment_timestamp'] = array(
'title' => t('Last comment time'),
'help' => t('Date and time of when the last comment was posted.'),
'field' => array(
'id' => 'comment_last_timestamp',
),
'sort' => array(
'id' => 'date',
),
'filter' => array(
'id' => 'date',
),
);
$data['forum_index']['comment_count'] = array(
'title' => t('Comment count'),
'help' => t('The number of comments a node has.'),
'field' => array(
'id' => 'numeric',
),
'filter' => array(
'id' => 'numeric',
),
'sort' => array(
'id' => 'standard',
),
'argument' => array(
'id' => 'standard',
),
);
return $data;
}
<?php
/**
* @file
* Contains \Drupal\forum\Tests\Views\ForumIntegrationTest.
*/
namespace Drupal\forum\Tests\Views;
use Drupal\views\Tests\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
/**
* Tests the forum integration into views.
*/
class ForumIntegrationTest extends ViewTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('forum_test_views');
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_forum_index');
public static function getInfo() {
return array(
'name' => 'Forum: Views data',
'description' => 'Tests the forum integration into views.',
'group' => 'Views module integration',
);
}
protected function setUp() {
parent::setUp();
ViewTestData::importTestViews(get_class($this), array('forum_test_views'));
}
/**
* Tests the integration.
*/
public function testForumIntegration() {
// Create a forum.
$entity_manager = $this->container->get('plugin.manager.entity');
$term = $entity_manager->getStorageController('taxonomy_term')->create(array('vid' => 'forums'));
$term->save();
$comment_storage_controller = $entity_manager->getStorageController('comment');
// Create some nodes which are part of this forum with some comments.
$nodes = array();
for ($i = 0; $i < 3; $i++) {
$node = $this->drupalCreateNode(array('type' => 'forum', 'taxonomy_forums' => array($term->id()), 'sticky' => $i == 0 ? NODE_STICKY : NODE_NOT_STICKY));
$nodes[] = $node;
}
$comments = array();
foreach ($nodes as $index => $node) {
for ($i = 0; $i <= $index; $i++) {
$comment = $comment_storage_controller->create(array('node_type' => 'node_type_forum', 'nid' => $node->id()));
$comment->save();
$comments[$comment->get('nid')->target_id][$comment->id()] = $comment;
}
}
$view = views_get_view('test_forum_index');
$this->executeView($view);
$expected_result = array();
$expected_result[] = array(
'nid' => $nodes[0]->id(),
'sticky' => NODE_STICKY,
'comment_count' => 1.
);
$expected_result[] = array(
'nid' => $nodes[1]->id(),
'sticky' => NODE_NOT_STICKY,
'comment_count' => 2.
);
$expected_result[] = array(
'nid' => $nodes[2]->id(),
'sticky' => NODE_NOT_STICKY,
'comment_count' => 3.
);
$column_map = array(
'nid' => 'nid',
'forum_index_sticky' => 'sticky',
'forum_index_comment_count' => 'comment_count',
);
$this->assertIdenticalResultset($view, $expected_result, $column_map);
}
}
name: 'Forum test views'
description: 'Provides default views for views forum tests.'
package: Testing
version: VERSION
core: 8.x
dependencies:
- forum
- views
hidden: true
base_field: nid
base_table: forum_index
core: 8.x
description: ''
status: '1'
display:
default:
display_plugin: default
id: default
display_title: Master
position: ''
display_options:
access:
type: none
cache:
type: none
query:
type: views_query
exposed_form:
type: basic
pager:
type: full
style:
type: default
row:
type: fields
fields:
nid:
table: forum_index
field: nid
id: nid
sticky:
id: sticky
table: forum_index
field: sticky
relationship: none
group_type: group
admin_label: ''
label: Sticky
exclude: '0'
alter:
alter_text: '0'
text: ''
make_link: '0'
path: ''
absolute: '0'
external: '0'
replace_spaces: '0'
path_case: none
trim_whitespace: '0'
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: '0'
max_length: ''
word_boundary: '1'
ellipsis: '1'
more_link: '0'
more_link_text: ''
more_link_path: ''
strip_tags: '0'
trim: '0'
preserve_tags: ''
html: '0'
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: '1'
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: '1'
empty: ''
hide_empty: '0'
empty_zero: '0'
hide_alter_empty: '1'
type: yes-no
type_custom_true: ''
type_custom_false: ''
not: '0'
plugin_id: boolean
comment_count:
id: comment_count
table: forum_index
field: comment_count
relationship: none
group_type: group
admin_label: ''
label: 'Comment count'
exclude: '0'
alter:
alter_text: '0'
text: ''
make_link: '0'
path: ''
absolute: '0'
external: '0'
replace_spaces: '0'
path_case: none
trim_whitespace: '0'
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: '0'
max_length: ''
word_boundary: '1'
ellipsis: '1'
more_link: '0'
more_link_text: ''
more_link_path: ''
strip_tags: '0'
trim: '0'
preserve_tags: ''
html: '0'
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: '1'
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: '1'
empty: ''
hide_empty: '0'
empty_zero: '0'
hide_alter_empty: '1'
set_precision: '0'
precision: '0'
decimal: .
separator: ','
format_plural: '0'
format_plural_singular: '1'
format_plural_plural: '@count'
prefix: ''
suffix: ''
plugin_id: numeric
filters: { }
sorts: { }
label: test_forum_index
module: views
id: test_forum_index
tag: ''
langcode: en
......@@ -31,6 +31,7 @@ class HandlerAllTest extends HandlerTestBase {
'field',
'filter',
'file',
'forum',
'history',
'language',
'locale',
......
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