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..048c065 --- /dev/null +++ b/core/modules/forum/config/install/views.view.forum_topic_lists.yml @@ -0,0 +1,235 @@ +base_field: nid +base_table: forum_index +core: 8.x +description: 'A list of new or active forum topics' +status: true +display: + default: + display_plugin: default + id: default + display_title: Master + position: 0 + display_options: + access: + type: none + options: { } + cache: + type: none + provider: views + query: + type: views_query + options: + disable_sql_rewrite: false + distinct: false + replica: false + query_comment: false + 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: '' + 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_singular: '1' + format_plural_plural: '@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: '' + 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 + 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' + 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 +label: 'Forum Topic Lists' +module: views +id: forum_topic_lists +tag: default +langcode: en +dependencies: + module: + - forum diff --git a/core/modules/forum/forum.views.inc b/core/modules/forum/forum.views.inc index fa7174f..11b706f 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' => array('base_table' => 'forum_index'), ); $data['forum_index']['nid'] = array( 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 133529a..0000000 --- a/core/modules/forum/src/Plugin/Block/ActiveTopicsBlock.php +++ /dev/null @@ -1,33 +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 8e690f0..0000000 --- a/core/modules/forum/src/Plugin/Block/ForumBlockBase.php +++ /dev/null @@ -1,92 +0,0 @@ -buildForumQuery()->execute(); - $elements = array(); - if ($node_title_list = node_title_list($result)) { - $elements['forum_list'] = $node_title_list; - $elements['forum_more'] = array( - '#theme' => 'more_link', - '#url' => 'forum', - '#title' => 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 array( - 'properties' => array( - 'administrative' => TRUE, - ), - 'block_count' => 5, - ); - } - - /** - * {@inheritdoc} - */ - protected function blockAccess(AccountInterface $account) { - return $account->hasPermission('access content'); - } - - /** - * {@inheritdoc} - */ - public function blockForm($form, FormStateInterface $form_state) { - $range = range(2, 20); - $form['block_count'] = array( - '#type' => 'select', - '#title' => 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 getCacheKeys() { - return array_merge(parent::getCacheKeys(), Cache::keyFromQuery($this->buildForumQuery())); - } - -} 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 635dab4..0000000 --- a/core/modules/forum/src/Plugin/Block/NewTopicsBlock.php +++ /dev/null @@ -1,32 +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/src/Tests/ForumBlockTest.php b/core/modules/forum/src/Tests/ForumBlockTest.php index 4b4942b..0574453 100644 --- a/core/modules/forum/src/Tests/ForumBlockTest.php +++ b/core/modules/forum/src/Tests/ForumBlockTest.php @@ -22,7 +22,7 @@ class ForumBlockTest extends WebTestBase { * * @var array */ - public static $modules = array('forum', 'block'); + public static $modules = array('forum', 'block', 'views'); /** * A user with various administrative privileges. @@ -50,13 +50,12 @@ 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. $topics = $this->createForumTopics(); - $this->assertLink(t('More'), 0, 'New forum topics block has a "more"-link.'); $this->assertLinkByHref('forum', 0, 'New forum topics block has a "more"-link.'); @@ -64,22 +63,6 @@ public function testNewForumTopicsBlock() { foreach ($topics as $topic) { $this->assertLink($topic, 0, format_string('Forum topic @topic found in the "New forum topics" block.', array('@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, array(3, 4))) { - $this->assertLink($topics[$index], 0, format_string('Forum topic @topic found in the "New forum topics" block.', array('@topic' => $topics[$index]))); - } - else { - $this->assertNoText($topics[$index], format_string('Forum topic @topic not found in the "New forum topics" block.', array('@topic' => $topics[$index]))); - } - } } /** @@ -110,7 +93,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.'); @@ -126,23 +109,6 @@ public function testActiveForumTopicsBlock() { $this->assertNoText($topics[$index], format_string('Forum topic @topic not found in the "Active forum topics" block.', array('@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, array(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/src/Tests/ForumNodeAccessTest.php b/core/modules/forum/src/Tests/ForumNodeAccessTest.php index 34ddd35..4f9393b 100644 --- a/core/modules/forum/src/Tests/ForumNodeAccessTest.php +++ b/core/modules/forum/src/Tests/ForumNodeAccessTest.php @@ -21,7 +21,7 @@ class ForumNodeAccessTest extends WebTestBase { * * @var array */ - public static $modules = array('node', 'comment', 'forum', 'taxonomy', 'tracker', 'node_access_test', 'block'); + public static $modules = array('node', 'comment', 'forum', 'taxonomy', 'tracker', 'node_access_test', 'block', 'views'); protected function setUp() { parent::setUp(); @@ -67,8 +67,8 @@ function testForumNodeAccess() { // 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/views/templates/views-more.html.twig b/core/modules/views/templates/views-more.html.twig index b161a65..c785d6b 100644 --- a/core/modules/views/templates/views-more.html.twig +++ b/core/modules/views/templates/views-more.html.twig @@ -7,8 +7,9 @@ * - view: The view object. * - more_url: The URL for the views "more" link. * - link_text: The text for the views "more" link. + * - attributes: HTML attributes for the containing element. * * @ingroup themeable */ #} -{{ link_text }} +{{ link_text }} diff --git a/core/modules/views/views.module b/core/modules/views/views.module index 3294836..944a910 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -16,6 +16,7 @@ use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Render\Element; use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\Core\Template\Attribute; use Drupal\views\Plugin\Derivative\ViewsLocalTask; use Drupal\Core\Template\AttributeArray; use Drupal\views\ViewExecutable;