diff --git a/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php b/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php index bb59f50..6909d1d 100644 --- a/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php +++ b/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php @@ -212,31 +212,6 @@ public function testBlockMigration() { ]; $this->assertEntity('book', [], 'sidebar_second', 'bartik', -4, $settings); - // Check forum block settings. - $settings = [ - 'id' => 'forum_active_block', - 'label' => '', - 'provider' => 'forum', - 'label_display' => '0', - 'block_count' => 3, - 'properties' => [ - 'administrative' => '1', - ], - ]; - $this->assertEntity('forum', [], 'sidebar_first', 'bartik', -8, $settings); - - $settings = [ - 'id' => 'forum_new_block', - 'label' => '', - 'provider' => 'forum', - 'label_display' => '0', - 'block_count' => 4, - 'properties' => [ - 'administrative' => '1', - ], - ]; - $this->assertEntity('forum_1', [], 'sidebar_first', 'bartik', -9, $settings); - // Check statistic block settings. $settings = [ 'id' => 'broken', diff --git a/core/modules/dblog/tests/src/Functional/DbLogTest.php b/core/modules/dblog/tests/src/Functional/DbLogTest.php index 5b82282..9f99842 100644 --- a/core/modules/dblog/tests/src/Functional/DbLogTest.php +++ b/core/modules/dblog/tests/src/Functional/DbLogTest.php @@ -24,7 +24,7 @@ class DbLogTest extends BrowserTestBase { * * @var array */ - public static $modules = ['dblog', 'node', 'forum', 'help', 'block']; + public static $modules = ['dblog', 'node', 'forum', 'help', 'block', 'views']; /** * A user with some relevant administrative permissions. 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/ForumIndexTest.php b/core/modules/forum/tests/src/Functional/ForumIndexTest.php index 5d0ccdf..0343846 100644 --- a/core/modules/forum/tests/src/Functional/ForumIndexTest.php +++ b/core/modules/forum/tests/src/Functional/ForumIndexTest.php @@ -16,7 +16,7 @@ class ForumIndexTest extends BrowserTestBase { * * @var array */ - public static $modules = ['taxonomy', 'comment', 'forum']; + public static $modules = ['taxonomy', 'comment', 'forum', 'views']; protected function setUp() { parent::setUp(); 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); diff --git a/core/modules/forum/tests/src/Functional/ForumTest.php b/core/modules/forum/tests/src/Functional/ForumTest.php index 9ba4be7..5286ec3 100644 --- a/core/modules/forum/tests/src/Functional/ForumTest.php +++ b/core/modules/forum/tests/src/Functional/ForumTest.php @@ -25,7 +25,7 @@ class ForumTest extends BrowserTestBase { * * @var array */ - public static $modules = ['taxonomy', 'comment', 'forum', 'node', 'block', 'menu_ui', 'help']; + public static $modules = ['taxonomy', 'comment', 'forum', 'node', 'block', 'menu_ui', 'help', 'views']; /** * A user with various administrative privileges. diff --git a/core/modules/forum/tests/src/Functional/ForumUninstallTest.php b/core/modules/forum/tests/src/Functional/ForumUninstallTest.php index c2d3848..547f1b3 100644 --- a/core/modules/forum/tests/src/Functional/ForumUninstallTest.php +++ b/core/modules/forum/tests/src/Functional/ForumUninstallTest.php @@ -21,7 +21,7 @@ class ForumUninstallTest extends BrowserTestBase { * * @var array */ - public static $modules = ['forum']; + public static $modules = ['forum', 'views']; /** * Tests if forum module uninstallation properly deletes the field. diff --git a/core/modules/forum/tests/src/Kernel/ForumValidationTest.php b/core/modules/forum/tests/src/Kernel/ForumValidationTest.php index 9b9661b..393fef5 100644 --- a/core/modules/forum/tests/src/Kernel/ForumValidationTest.php +++ b/core/modules/forum/tests/src/Kernel/ForumValidationTest.php @@ -18,7 +18,7 @@ class ForumValidationTest extends EntityKernelTestBase { * * @var array */ - public static $modules = ['node', 'options', 'comment', 'taxonomy', 'forum']; + public static $modules = ['node', 'options', 'comment', 'taxonomy', 'forum', 'views']; /** * Tests the forum validation constraints. diff --git a/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumTest.php b/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumTest.php index 6f5d48c..e9ef633 100644 --- a/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumTest.php +++ b/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumTest.php @@ -24,6 +24,7 @@ class MigrateForumTest extends MigrateNodeTestBase { 'forum', 'menu_ui', 'taxonomy', + 'views', ]; /** diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php index 3717606..039cf31 100644 --- a/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php +++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php @@ -69,7 +69,7 @@ protected function getEntityCounts() { 'user' => 7, 'user_role' => 6, 'menu_link_content' => 4, - 'view' => 16, + 'view' => 17, 'date_format' => 11, 'entity_form_display' => 29, 'entity_form_mode' => 1, diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php index 3cfe4bc..6d9a36b 100644 --- a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php +++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php @@ -73,7 +73,7 @@ protected function getEntityCounts() { 'user' => 4, 'user_role' => 3, 'menu_link_content' => 7, - 'view' => 16, + 'view' => 17, 'date_format' => 11, 'entity_form_display' => 17, 'entity_form_mode' => 1, diff --git a/core/modules/node/tests/src/Functional/NodeAccessPagerTest.php b/core/modules/node/tests/src/Functional/NodeAccessPagerTest.php index ad6cc54..d2dac3c 100644 --- a/core/modules/node/tests/src/Functional/NodeAccessPagerTest.php +++ b/core/modules/node/tests/src/Functional/NodeAccessPagerTest.php @@ -21,7 +21,7 @@ class NodeAccessPagerTest extends BrowserTestBase { * * @var array */ - public static $modules = ['node_access_test', 'comment', 'forum']; + public static $modules = ['node_access_test', 'comment', 'forum', 'views']; protected function setUp() { parent::setUp(); diff --git a/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php b/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php index dc053a8..0ffe763 100644 --- a/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php +++ b/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php @@ -35,6 +35,7 @@ class MigrateNodeTest extends MigrateDrupal7TestBase { 'taxonomy', 'telephone', 'text', + 'views', ]; /** diff --git a/core/modules/system/tests/src/Functional/Path/UrlAlterFunctionalTest.php b/core/modules/system/tests/src/Functional/Path/UrlAlterFunctionalTest.php index 2717741..3149efe 100644 --- a/core/modules/system/tests/src/Functional/Path/UrlAlterFunctionalTest.php +++ b/core/modules/system/tests/src/Functional/Path/UrlAlterFunctionalTest.php @@ -19,7 +19,7 @@ class UrlAlterFunctionalTest extends BrowserTestBase { * * @var array */ - public static $modules = ['path', 'forum', 'url_alter_test']; + public static $modules = ['path', 'forum', 'url_alter_test', 'views']; /** * Test that URL altering works and that it occurs in the correct order. diff --git a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php index 474969d..d848855 100644 --- a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php @@ -24,6 +24,7 @@ class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase { 'taxonomy', 'telephone', 'text', + 'views', ]; /** diff --git a/core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php b/core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php index 6abb5cc..e39aade 100644 --- a/core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php +++ b/core/tests/Drupal/KernelTests/Config/DefaultConfigTest.php @@ -27,7 +27,7 @@ class DefaultConfigTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = ['system', 'user']; + public static $modules = ['system', 'user', 'views']; /** * The following config entries are changed on module install. diff --git a/core/tests/Drupal/KernelTests/Core/Extension/ModuleConfigureRouteTest.php b/core/tests/Drupal/KernelTests/Core/Extension/ModuleConfigureRouteTest.php index 96e469a..06ebc92 100644 --- a/core/tests/Drupal/KernelTests/Core/Extension/ModuleConfigureRouteTest.php +++ b/core/tests/Drupal/KernelTests/Core/Extension/ModuleConfigureRouteTest.php @@ -17,7 +17,7 @@ class ModuleConfigureRouteTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = ['system', 'user']; + public static $modules = ['system', 'user', 'views']; /** * @var \Drupal\Core\Routing\RouteProviderInterface