# 修改与“新主题”相关的变量

**URL:** <https://meta.discourse.org/t/modifying-variables-related-to-new-topic/195289>\
**Category:** Development\
**Created:** [2021年六月28日 21:40 UTC](https://meta.discourse.org/t/modifying-variables-related-to-new-topic/195289 "2021-06-28T21:40:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Connor\_Parrish](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/connor_parrish/32/225463_2.png) [@Connor\_Parrish](https://meta.discourse.org/u/Connor_Parrish)\
**Post date:** [2021年六月28日 21:40 UTC](https://meta.discourse.org/t/modifying-variables-related-to-new-topic/195289/1 "2021-06-28T21:40:04Z")

</div>

我正在尝试修改 `tag-show.js` 中 `createTopicDisabled` 的行为。但我似乎无法像在这里看到的那样覆盖它。

* * *

我尝试过像这样使用 `api.modifyClass()` 和 `api.modifyClassStatic()`：

```javascript
api.modifyClass("controller:tag-show", {
    @discourseComputed(
        "canCreateTopic",
        "category",
        "canCreateTopicOnCategory",
        "tag",
        "canCreateTopicOnTag")
    createTopicDisabled(
        canCreateTopic,
        category,
        canCreateTopicOnCategory,
        tag,
        canCreateTopicOnTag)
    {
        return false;
    }
})

```

还有这种：

```javascript
api.modifyClass("controller:tag-show", {
    createTopicDisabled: function() { return false; }
})

```

以及各种其他变体。

* * *

我还尝试获取默认控制器并重新打开它，这在覆盖 actions 时工作正常。

```javascript
const TagShowController = require('discourse/controllers/tag-show').default;
TagShowController.reopen({
    createTopicDisabled: function() {
        return false;
    }
})

```

到目前为止，这些方法都没有真正生效。任何帮助都将不胜感激。
