diff --git a/core/modules/forum/config/install/views.view.forum_topic_lists.yml b/core/modules/forum/config/install/views.view.forum_topic_lists.yml new file mode 100644 index 0000000..a58fa7e --- /dev/null +++ b/core/modules/forum/config/install/views.view.forum_topic_lists.yml @@ -0,0 +1,253 @@ +uuid: a2d0c233-4de5-48f2-a654-b70ea3e150bf +langcode: en +status: true +dependencies: { } +_core: + default_config_hash: Ldd84yxo2nrG4Og-ftUvBHNQK8U2rJQ0uGzMTQibe6g +id: forum_topic_lists +label: 'Forum Topic Lists' +module: views +description: 'A list of new or active forum topics' +tag: default +base_table: forum_index +base_field: nid +core: 8.x +display: + default: + display_plugin: default + id: default + display_title: Master + position: 0 + display_options: + access: + type: none + options: { } + cache: + type: none + options: { } + query: + type: views_query + options: + disable_sql_rewrite: false + distinct: false + replica: false + query_comment: '' + query_tags: { } + exposed_form: + type: basic + options: + submit_button: Apply + reset_button: false + reset_button_label: Reset + exposed_sorts_label: 'Sort by' + expose_sort_order: true + sort_asc_label: Asc + sort_desc_label: Desc + pager: + type: some + options: + items_per_page: 5 + offset: 0 + style: + type: html_list + options: + grouping: { } + row_class: '' + default_row_class: true + type: ul + wrapper_class: item-list + class: '' + row: + type: fields + fields: + nid: + id: nid + table: forum_index + field: nid + relationship: none + plugin_id: numeric + group_type: group + admin_label: '' + label: '' + exclude: true + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: null + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + set_precision: false + precision: 0 + decimal: . + separator: ',' + format_plural: false + format_plural_string: "1\x03@count" + prefix: '' + suffix: '' + title: + id: title + table: forum_index + field: title + relationship: none + group_type: group + admin_label: '' + label: '' + exclude: false + alter: + alter_text: false + text: '' + make_link: true + path: 'node/{{ nid }}' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: null + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + plugin_id: standard + filters: { } + sorts: { } + title: 'New forum topics' + header: { } + footer: { } + empty: { } + relationships: { } + arguments: { } + use_more: true + use_more_always: true + use_more_text: More + link_display: custom_url + link_url: forum + display_extenders: { } + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_interface' + tags: { } + block_1: + display_plugin: block + id: block_1 + display_title: 'Active forum topics' + position: 1 + display_options: + display_description: 'Displays a list of active forum topics' + sorts: + last_comment_timestamp: + id: last_comment_timestamp + table: forum_index + field: last_comment_timestamp + relationship: none + group_type: group + admin_label: '' + order: DESC + exposed: false + expose: + label: '' + granularity: second + plugin_id: date + defaults: + sorts: false + title: false + use_more: true + use_more_always: true + use_more_text: true + block_description: 'Active forum topics' + title: 'Active forum topics' + display_extenders: { } + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_interface' + tags: { } + block_2: + display_plugin: block + id: block_2 + display_title: 'New forum topics' + position: 2 + display_options: + display_description: 'Displays a list of new forum topics' + sorts: + created: + id: created + table: forum_index + field: created + relationship: none + group_type: group + admin_label: '' + order: DESC + exposed: false + expose: + label: '' + granularity: second + plugin_id: date + defaults: + sorts: false + block_description: 'New forum topics' + link_url: /forum + display_extenders: { } + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_interface' + tags: { } diff --git a/core/modules/forum/forum.views.inc b/core/modules/forum/forum.views.inc index 5f67af5..29512c3 100644 --- a/core/modules/forum/forum.views.inc +++ b/core/modules/forum/forum.views.inc @@ -15,6 +15,7 @@ function forum_views_data() { 'field' => 'nid', 'title' => t('Forum content'), 'access query tag' => 'node_access', + 'query metadata' => ['base_table' => 'forum_index'], ]; $data['forum_index']['nid'] = [ diff --git a/core/modules/forum/forum.views_execution.inc b/core/modules/forum/forum.views_execution.inc new file mode 100644 index 0000000..dbf0ab0 --- /dev/null +++ b/core/modules/forum/forum.views_execution.inc @@ -0,0 +1,18 @@ +storage->id() == 'forum_topic_lists') { + // Append some descriptive text to provide context to the 'Read More' link. + $variables['attributes']['title'] = $view->getTitle(); + } +} diff --git a/core/modules/forum/src/Plugin/Block/ActiveTopicsBlock.php b/core/modules/forum/src/Plugin/Block/ActiveTopicsBlock.php deleted file mode 100644 index ac8d828..0000000 --- a/core/modules/forum/src/Plugin/Block/ActiveTopicsBlock.php +++ /dev/null @@ -1,28 +0,0 @@ -fields('f') - ->addTag('node_access') - ->addMetaData('base_table', 'forum_index') - ->orderBy('f.last_comment_timestamp', 'DESC') - ->range(0, $this->configuration['block_count']); - } - -} diff --git a/core/modules/forum/src/Plugin/Block/ForumBlockBase.php b/core/modules/forum/src/Plugin/Block/ForumBlockBase.php deleted file mode 100644 index 8095cef..0000000 --- a/core/modules/forum/src/Plugin/Block/ForumBlockBase.php +++ /dev/null @@ -1,96 +0,0 @@ -buildForumQuery()->execute(); - $elements = []; - if ($node_title_list = node_title_list($result)) { - $elements['forum_list'] = $node_title_list; - $elements['forum_more'] = [ - '#type' => 'more_link', - '#url' => Url::fromRoute('forum.index'), - '#attributes' => ['title' => $this->t('Read the latest forum topics.')], - ]; - } - return $elements; - } - - /** - * Builds the select query to use for this forum block. - * - * @return \Drupal\Core\Database\Query\Select - * A Select object. - */ - abstract protected function buildForumQuery(); - - /** - * {@inheritdoc} - */ - public function defaultConfiguration() { - return [ - 'properties' => [ - 'administrative' => TRUE, - ], - 'block_count' => 5, - ]; - } - - /** - * {@inheritdoc} - */ - protected function blockAccess(AccountInterface $account) { - return AccessResult::allowedIfHasPermission($account, 'access content'); - } - - /** - * {@inheritdoc} - */ - public function blockForm($form, FormStateInterface $form_state) { - $range = range(2, 20); - $form['block_count'] = [ - '#type' => 'select', - '#title' => $this->t('Number of topics'), - '#default_value' => $this->configuration['block_count'], - '#options' => array_combine($range, $range), - ]; - return $form; - } - - /** - * {@inheritdoc} - */ - public function blockSubmit($form, FormStateInterface $form_state) { - $this->configuration['block_count'] = $form_state->getValue('block_count'); - } - - /** - * {@inheritdoc} - */ - public function getCacheContexts() { - return Cache::mergeContexts(parent::getCacheContexts(), ['user.node_grants:view']); - } - - /** - * {@inheritdoc} - */ - public function getCacheTags() { - return Cache::mergeTags(parent::getCacheTags(), ['node_list']); - } - -} diff --git a/core/modules/forum/src/Plugin/Block/NewTopicsBlock.php b/core/modules/forum/src/Plugin/Block/NewTopicsBlock.php deleted file mode 100644 index d57628f..0000000 --- a/core/modules/forum/src/Plugin/Block/NewTopicsBlock.php +++ /dev/null @@ -1,28 +0,0 @@ -fields('f') - ->addTag('node_access') - ->addMetaData('base_table', 'forum_index') - ->orderBy('f.created', 'DESC') - ->range(0, $this->configuration['block_count']); - } - -} diff --git a/core/modules/forum/tests/src/Functional/ForumBlockTest.php b/core/modules/forum/tests/src/Functional/ForumBlockTest.php index b231f6d..0604c22 100644 --- a/core/modules/forum/tests/src/Functional/ForumBlockTest.php +++ b/core/modules/forum/tests/src/Functional/ForumBlockTest.php @@ -18,7 +18,7 @@ class ForumBlockTest extends BrowserTestBase { * * @var array */ - public static $modules = ['forum', 'block']; + public static $modules = ['forum', 'block', 'views']; /** * A user with various administrative privileges. @@ -46,7 +46,7 @@ public function testNewForumTopicsBlock() { $this->drupalLogin($this->adminUser); // Enable the new forum topics block. - $block = $this->drupalPlaceBlock('forum_new_block'); + $block = $this->drupalPlaceBlock('views_block:forum_topic_lists-block_2'); $this->drupalGet(''); // Create 5 forum topics. @@ -59,22 +59,6 @@ public function testNewForumTopicsBlock() { foreach ($topics as $topic) { $this->assertLink($topic, 0, format_string('Forum topic @topic found in the "New forum topics" block.', ['@topic' => $topic])); } - - // Configure the new forum topics block to only show 2 topics. - $block->getPlugin()->setConfigurationValue('block_count', 2); - $block->save(); - - $this->drupalGet(''); - // We expect only the 2 most recent forum topics to appear in the "New forum - // topics" block. - for ($index = 0; $index < 5; $index++) { - if (in_array($index, [3, 4])) { - $this->assertLink($topics[$index], 0, format_string('Forum topic @topic found in the "New forum topics" block.', ['@topic' => $topics[$index]])); - } - else { - $this->assertNoText($topics[$index], format_string('Forum topic @topic not found in the "New forum topics" block.', ['@topic' => $topics[$index]])); - } - } } /** @@ -105,7 +89,7 @@ public function testActiveForumTopicsBlock() { } // Enable the block. - $block = $this->drupalPlaceBlock('forum_active_block'); + $block = $this->drupalPlaceBlock('views_block:forum_topic_lists-block_1'); $this->drupalGet(''); $this->assertLink(t('More'), 0, 'Active forum topics block has a "more"-link.'); $this->assertLinkByHref('forum', 0, 'Active forum topics block has a "more"-link.'); @@ -121,23 +105,6 @@ public function testActiveForumTopicsBlock() { $this->assertNoText($topics[$index], format_string('Forum topic @topic not found in the "Active forum topics" block.', ['@topic' => $topics[$index]])); } } - - // Configure the active forum block to only show 2 topics. - $block->getPlugin()->setConfigurationValue('block_count', 2); - $block->save(); - - $this->drupalGet(''); - - // We expect only the 2 forum topics with most recent comments to appear in - // the "Active forum topics" block. - for ($index = 0; $index < 10; $index++) { - if (in_array($index, [3, 4])) { - $this->assertLink($topics[$index], 0, 'Forum topic found in the "Active forum topics" block.'); - } - else { - $this->assertNoText($topics[$index], 'Forum topic not found in the "Active forum topics" block.'); - } - } } /** diff --git a/core/modules/forum/tests/src/Functional/ForumNodeAccessTest.php b/core/modules/forum/tests/src/Functional/ForumNodeAccessTest.php index 9849084..77611f1 100644 --- a/core/modules/forum/tests/src/Functional/ForumNodeAccessTest.php +++ b/core/modules/forum/tests/src/Functional/ForumNodeAccessTest.php @@ -17,7 +17,7 @@ class ForumNodeAccessTest extends BrowserTestBase { * * @var array */ - public static $modules = ['node', 'comment', 'forum', 'taxonomy', 'tracker', 'node_access_test', 'block']; + public static $modules = ['node', 'comment', 'forum', 'taxonomy', 'tracker', 'node_access_test', 'block', 'views']; protected function setUp() { parent::setUp(); @@ -62,8 +62,8 @@ public function testForumNodeAccess() { $this->assertTrue(!empty($public_node), 'New public forum node found in database.'); // Enable the new and active forum blocks. - $this->drupalPlaceBlock('forum_active_block'); - $this->drupalPlaceBlock('forum_new_block'); + $this->drupalPlaceBlock('views_block:forum_topic_lists-block_1'); + $this->drupalPlaceBlock('views_block:forum_topic_lists-block_2'); // Test for $access_user. $this->drupalLogin($access_user);