Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] [tags] feat: option to display tags in DiscussionsSearchSource #4055

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions extensions/tags/extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions extensions/tags/js/src/admin/components/TagsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ export default class TagsPage extends ExtensionPage {
<input className="FormControl" type="number" min={minSecondaryTags()} bidi={maxSecondaryTags} />
</div>
</div>
<div className="Form-group">
{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'),
})}
</div>
<div className="Form-group">{this.submitButton()}</div>
</div>
</div>
Expand Down
16 changes: 16 additions & 0 deletions extensions/tags/js/src/forum/addTagsToDiscussionSearch.tsx
Original file line number Diff line number Diff line change
@@ -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<boolean>('showTagsInDiscussionSearchResults') && includes.push('tags');
});

extend(DiscussionsSearchItem.prototype, 'viewItems', function (items) {
app.forum.attribute<boolean>('showTagsInDiscussionSearchResults') &&
items.add('tags', <div className="DiscussionSearchResult-tags">{tagsLabel(this.discussion.tags())}</div>, 100);
});
}
2 changes: 2 additions & 0 deletions extensions/tags/js/src/forum/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import addTagFilter from './addTagFilter';
import addTagLabels from './addTagLabels';
import addTagControl from './addTagControl';
import addTagComposer from './addTagComposer';
import addTagsToDiscussionSearch from './addTagsToDiscussionSearch';

export { default as extend } from './extend';

Expand All @@ -18,6 +19,7 @@ app.initializers.add('flarum-tags', function () {
addTagLabels();
addTagControl();
addTagComposer();
addTagsToDiscussionSearch();
});

// Expose compat API
Expand Down
3 changes: 3 additions & 0 deletions extensions/tags/locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions framework/core/js/dist-typings/forum/components/Search.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading