From bc9c0cc9476eea7bd310c9ccaa3152e7c28bcbc7 Mon Sep 17 00:00:00 2001 From: IanM Date: Wed, 2 Oct 2024 11:32:38 +0100 Subject: [PATCH] feat: option to display tags in DiscussionsSearchSource --- extensions/tags/extend.php | 2 ++ .../tags/js/src/admin/components/TagsPage.js | 8 ++++++++ .../js/src/forum/addTagsToDiscussionSearch.tsx | 16 ++++++++++++++++ extensions/tags/js/src/forum/index.ts | 2 ++ extensions/tags/locale/en.yml | 3 +++ 5 files changed, 31 insertions(+) create mode 100644 extensions/tags/js/src/forum/addTagsToDiscussionSearch.tsx diff --git a/extensions/tags/extend.php b/extensions/tags/extend.php index 4ca124e5b4..4f42784a37 100644 --- a/extensions/tags/extend.php +++ b/extensions/tags/extend.php @@ -100,6 +100,8 @@ ->prepareDataForSerialization(LoadForumTagsRelationship::class), (new Extend\Settings()) + ->default('flarum-tags.show_tags_in_discussion_search_results', false) + ->serializeToForum('showTagsInDiscussionSearchResults', 'flarum-tags.show_tags_in_discussion_search_results', 'boolVal') ->serializeToForum('minPrimaryTags', 'flarum-tags.min_primary_tags') ->serializeToForum('maxPrimaryTags', 'flarum-tags.max_primary_tags') ->serializeToForum('minSecondaryTags', 'flarum-tags.min_secondary_tags') diff --git a/extensions/tags/js/src/admin/components/TagsPage.js b/extensions/tags/js/src/admin/components/TagsPage.js index 4564869bb9..24f4725a59 100644 --- a/extensions/tags/js/src/admin/components/TagsPage.js +++ b/extensions/tags/js/src/admin/components/TagsPage.js @@ -118,6 +118,14 @@ export default class TagsPage extends ExtensionPage { +
+ {this.buildSettingComponent({ + setting: 'flarum-tags.show_tags_in_discussion_search_results', + type: 'boolean', + label: app.translator.trans('flarum-tags.admin.tag_settings.show_tags_in_discussion_search_results.label'), + help: app.translator.trans('flarum-tags.admin.tag_settings.show_tags_in_discussion_search_results.help'), + })} +
{this.submitButton()}
diff --git a/extensions/tags/js/src/forum/addTagsToDiscussionSearch.tsx b/extensions/tags/js/src/forum/addTagsToDiscussionSearch.tsx new file mode 100644 index 0000000000..86de0f17a1 --- /dev/null +++ b/extensions/tags/js/src/forum/addTagsToDiscussionSearch.tsx @@ -0,0 +1,16 @@ +import app from 'flarum/forum/app'; +import { extend } from 'flarum/common/extend'; +import DiscussionsSearchItem from 'flarum/forum/components/DiscussionsSearchItem'; +import DiscussionsSearchSource from 'flarum/forum/components/DiscussionsSearchSource'; +import tagsLabel from '../common/helpers/tagsLabel'; + +export default function addTagsToDiscussionSearch() { + extend(DiscussionsSearchSource.prototype, 'includes', function (includes) { + app.forum.attribute('showTagsInDiscussionSearchResults') && includes.push('tags'); + }); + + extend(DiscussionsSearchItem.prototype, 'viewItems', function (items) { + app.forum.attribute('showTagsInDiscussionSearchResults') && + items.add('tags',
{tagsLabel(this.discussion.tags())}
, 100); + }); +} diff --git a/extensions/tags/js/src/forum/index.ts b/extensions/tags/js/src/forum/index.ts index 838f669481..f9ba52d5a3 100644 --- a/extensions/tags/js/src/forum/index.ts +++ b/extensions/tags/js/src/forum/index.ts @@ -18,10 +18,12 @@ app.initializers.add('flarum-tags', function () { addTagLabels(); addTagControl(); addTagComposer(); + addTagsToDiscussionSearch(); }); // Expose compat API import tagsCompat from './compat'; import { compat } from '@flarum/core/forum'; +import addTagsToDiscussionSearch from './addTagsToDiscussionSearch'; Object.assign(compat, tagsCompat); diff --git a/extensions/tags/locale/en.yml b/extensions/tags/locale/en.yml index 3890539d2d..47f5830a31 100644 --- a/extensions/tags/locale/en.yml +++ b/extensions/tags/locale/en.yml @@ -49,6 +49,9 @@ flarum-tags: required_primary_text: Enter the minimum and maximum number of primary tags that may be applied to a discussion. required_secondary_heading: Required Number of Secondary Tags required_secondary_text: Enter the minimum and maximum number of secondary tags that may be applied to a discussion. + show_tags_in_discussion_search_results: + label: Show Tags in Discussion Search Results + help: "When enabled, tags will be displayed in the search results for discussions." title: Tag Settings # These translations are used in the Tags page.