diff --git a/extensions/tags/js/admin/src/components/EditTagModal.js b/extensions/tags/js/admin/src/components/EditTagModal.js
index 97d6fa3ad..81d48cade 100644
--- a/extensions/tags/js/admin/src/components/EditTagModal.js
+++ b/extensions/tags/js/admin/src/components/EditTagModal.js
@@ -1,5 +1,6 @@
import Modal from 'flarum/components/Modal';
import Button from 'flarum/components/Button';
+import Switch from 'flarum/components/Switch';
import { slug } from 'flarum/utils/string';
import tagLabel from 'tags/helpers/tagLabel';
@@ -18,6 +19,7 @@ export default class EditTagModal extends Modal {
this.slug = m.prop(this.tag.slug() || '');
this.description = m.prop(this.tag.description() || '');
this.color = m.prop(this.tag.color() || '');
+ this.isHidden = m.prop(this.tag.isHidden() || '');
}
className() {
@@ -60,11 +62,20 @@ export default class EditTagModal extends Modal {
+
+
+
+
+
+
{Button.component({
type: 'submit',
className: 'Button Button--primary EditTagModal-save',
- loading: this._loading,
+ loading: this.loading,
children: 'Save Changes'
})}
{this.tag.exists ? (
@@ -81,17 +92,18 @@ export default class EditTagModal extends Modal {
onsubmit(e) {
e.preventDefault();
- this._loading = true;
+ this.loading = true;
this.tag.save({
name: this.name(),
slug: this.slug(),
description: this.description(),
- color: this.color()
+ color: this.color(),
+ isHidden: this.isHidden()
}).then(
() => this.hide(),
() => {
- this._loading = false;
+ this.loading = false;
m.redraw();
}
);
diff --git a/extensions/tags/js/lib/models/Tag.js b/extensions/tags/js/lib/models/Tag.js
index 391a4a7bc..04cda1519 100644
--- a/extensions/tags/js/lib/models/Tag.js
+++ b/extensions/tags/js/lib/models/Tag.js
@@ -10,12 +10,12 @@ export default class Tag extends mixin(Model, {
color: Model.attribute('color'),
backgroundUrl: Model.attribute('backgroundUrl'),
backgroundMode: Model.attribute('backgroundMode'),
- iconUrl: Model.attribute('iconUrl'),
position: Model.attribute('position'),
parent: Model.hasOne('parent'),
defaultSort: Model.attribute('defaultSort'),
isChild: Model.attribute('isChild'),
+ isHidden: Model.attribute('isHidden'),
discussionsCount: Model.attribute('discussionsCount'),
lastTime: Model.attribute('lastTime', Model.transformDate),
diff --git a/extensions/tags/migrations/2015_02_24_000000_create_tags_table.php b/extensions/tags/migrations/2015_02_24_000000_create_tags_table.php
index 855043944..7fcc298aa 100644
--- a/extensions/tags/migrations/2015_02_24_000000_create_tags_table.php
+++ b/extensions/tags/migrations/2015_02_24_000000_create_tags_table.php
@@ -21,12 +21,12 @@ class CreateTagsTable extends Migration
$table->string('color', 50)->nullable();
$table->string('background_path', 100)->nullable();
$table->string('background_mode', 100)->nullable();
- $table->string('icon_path', 100)->nullable();
$table->integer('position')->nullable();
$table->integer('parent_id')->unsigned()->nullable();
$table->string('default_sort', 50)->nullable();
$table->boolean('is_restricted')->default(0);
+ $table->boolean('is_hidden')->default(0);
$table->integer('discussions_count')->unsigned()->default(0);
$table->integer('last_time')->unsigned()->nullable();
diff --git a/extensions/tags/src/Api/TagSerializer.php b/extensions/tags/src/Api/TagSerializer.php
index 24db8da42..9bfaa9e3e 100644
--- a/extensions/tags/src/Api/TagSerializer.php
+++ b/extensions/tags/src/Api/TagSerializer.php
@@ -20,6 +20,7 @@ class TagSerializer extends Serializer
'position' => $tag->position === null ? null : (int) $tag->position,
'defaultSort' => $tag->default_sort,
'isChild' => (bool) $tag->parent_id,
+ 'isHidden' => (bool) $tag->is_hidden,
'lastTime' => $tag->last_time ? $tag->last_time->toRFC3339String() : null,
'canStartDiscussion' => $tag->can($this->actor, 'startDiscussion')
];
diff --git a/extensions/tags/src/Commands/CreateTagHandler.php b/extensions/tags/src/Commands/CreateTagHandler.php
index 869acc20a..b2c3ec769 100644
--- a/extensions/tags/src/Commands/CreateTagHandler.php
+++ b/extensions/tags/src/Commands/CreateTagHandler.php
@@ -34,7 +34,8 @@ class CreateTagHandler
array_get($data, 'attributes.name'),
array_get($data, 'attributes.slug'),
array_get($data, 'attributes.description'),
- array_get($data, 'attributes.color')
+ array_get($data, 'attributes.color'),
+ array_get($data, 'attributes.isHidden')
);
$tag->save();
diff --git a/extensions/tags/src/Commands/EditTagHandler.php b/extensions/tags/src/Commands/EditTagHandler.php
index a14422e13..81741b184 100644
--- a/extensions/tags/src/Commands/EditTagHandler.php
+++ b/extensions/tags/src/Commands/EditTagHandler.php
@@ -50,6 +50,10 @@ class EditTagHandler
$tag->color = $attributes['color'];
}
+ if (isset($attributes['isHidden'])) {
+ $tag->is_hidden = (bool) $attributes['isHidden'];
+ }
+
if (isset($attributes['isRestricted'])) {
$tag->is_restricted = (bool) $attributes['isRestricted'];
}
diff --git a/extensions/tags/src/Listeners/AddTagGambit.php b/extensions/tags/src/Listeners/AddTagGambit.php
index 80081af59..c642189f1 100755
--- a/extensions/tags/src/Listeners/AddTagGambit.php
+++ b/extensions/tags/src/Listeners/AddTagGambit.php
@@ -1,17 +1,39 @@
listen(RegisterDiscussionGambits::class, [$this, 'registerTagGambit']);
+ $events->listen(DiscussionSearchWillBePerformed::class, [$this, 'hideTags']);
}
public function registerTagGambit(RegisterDiscussionGambits $event)
{
$event->gambits->add('Flarum\Tags\Gambits\TagGambit');
}
+
+ public function hideTags(DiscussionSearchWillBePerformed $event)
+ {
+ $query = $event->search->getQuery();
+
+ foreach ($event->search->getActiveGambits() as $gambit) {
+ if ($gambit instanceof TagGambit) {
+ return;
+ }
+ }
+
+ $query->whereNotExists(function ($query) {
+ return $query->select(app('flarum.db')->raw(1))
+ ->from('discussions_tags')
+ ->whereIn('tag_id', Tag::where('is_hidden', 1)->lists('id'))
+ ->whereRaw('discussion_id = discussions.id');
+ });
+ }
}
diff --git a/extensions/tags/src/Tag.php b/extensions/tags/src/Tag.php
index 2a5c6a971..29f45071c 100644
--- a/extensions/tags/src/Tag.php
+++ b/extensions/tags/src/Tag.php
@@ -45,9 +45,10 @@ class Tag extends Model
* @param string $slug
* @param string $description
* @param string $color
+ * @param bool $isHidden
* @return static
*/
- public static function build($name, $slug, $description, $color)
+ public static function build($name, $slug, $description, $color, $isHidden)
{
$tag = new static;
@@ -55,6 +56,7 @@ class Tag extends Model
$tag->slug = $slug;
$tag->description = $description;
$tag->color = $color;
+ $tag->is_hidden = $isHidden;
return $tag;
}