I want to implement this feature. If the tag is selected as "is_hidden", the content posted by the specified user group in the tag can still be displayed in all discussions. I wrote my own filter IgnoreHiddenTagsFromAllDiscussionsPage.php
namespace Nodeloc\IgnoreHiddenTags\Filter;
use Flarum\Filter\FilterState;
use Flarum\Query\QueryCriteria;
use Flarum\Tags\Tag;
class IgnoreHiddenTagsFromAllDiscussionsPage
{
public function __invoke(FilterState $filter, QueryCriteria $queryCriteria)
{
if (count($filter->getActiveFilters()) > 0) {
return;
}
$filter->getQuery()->where(function ($query) {
$query->whereNotIn('discussions.id', function ($query) {
return $query->select('discussion_id')
->from('discussion_tag')
->whereIn('tag_id', Tag::where('is_hidden', 1)->pluck('id'))
->whereNotExists(function ($query) {
return $query->selectRaw('1')
->from('users')
->join('group_user', 'group_user.user_id', '=', 'users.id')
->join('groups', 'groups.id', '=', 'group_user.group_id')
->join('group_permission', 'group_permission.group_id', '=', 'groups.id')
->where('group_permission.permission', 'ignorehiddentags.allowIgnoreGroup')
->whereRaw('users.id = discussions.user_id');
});
});
});
}
}
and then inherited Provide to implement IgnoreServiceProvider.php in order to remove the original filter.
namespace Nodeloc\IgnoreHiddenTags\Provider;
use Flarum\Foundation\AbstractServiceProvider;
use Nodeloc\IgnoreHiddenTags\Filter\IgnoreHiddenTagsFromAllDiscussionsPage;
use Flarum\Tags\Filter\HideHiddenTagsFromAllDiscussionsPage;
class IgnoreServiceProvider extends AbstractServiceProvider
{
public function register()
{
$this->app->extend('flarum.filter.filter_mutators', function ($mutators) {
unset($mutators[HideHiddenTagsFromAllDiscussionsPage::class]);
$mutators[IgnoreHiddenTagsFromAllDiscussionsPage::class] = $this->app->make(IgnoreHiddenTagsFromAllDiscussionsPage::class);
return $mutators;
});
}
}
And in the extend.php, I add the filter and provider.
return [
(new Extend\Frontend('admin'))
->js(__DIR__.'/js/dist/admin.js'),
new Extend\Locales(__DIR__.'/locale'),
(new Extend\ServiceProvider(IgnoreServiceProvider::class)),
(new Extend\Filter(DiscussionFilterer::class))
->addFilterMutator(IgnoreHiddenTagsFromAllDiscussionsPage::class),
(new Extend\ApiSerializer(ForumSerializer::class))
->attribute('allowIgnoreGroup', function (ForumSerializer $serializer) {
return $serializer->getActor()->hasPermission("ignorehiddentags.allowIgnoreGroup");
}),
];
But now the original filter is still in effect. Could you please tell me why this is happening? Thank you.