# 無効なアイテムが top\_menu 設定に追加できてしまう

**URL:** https://meta.discourse.org/t/invalid-items-can-be-added-to-the-top-menu-setting/80074
**Category:** Bug
**Created:** [2018 年 2 月 8 日午前 2:23 UTC](https://meta.discourse.org/t/invalid-items-can-be-added-to-the-top-menu-setting/80074 "2018-02-08T02:23:37Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [2018 年 2 月 8 日午前 2:23 UTC](https://meta.discourse.org/t/invalid-items-can-be-added-to-the-top-menu-setting/80074/1 "2018-02-08T02:23:37Z")

</div>

It is possible to add invalid menu items to the top\_menu setting. If an invalid item is the first item in the `SiteSetting.top_menu` list, the site will broken in a way that can’t be fixed through the UI.

I’m not sure if there’s ever a reason to be able to add custom menu items to the top\_menu list.

 ![07%20PM](https://global.discourse-cdn.com/meta/original/3X/f/8/f88ee8638e66903aeed1748ac70143b98a370911.png)

![34%20PM](https://global.discourse-cdn.com/meta/original/3X/2/9/29ea188e3ceb1e2772d00ae23e9fac328606864a.png)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2018 年 2 月 8 日午前 2:25 UTC](https://meta.discourse.org/t/invalid-items-can-be-added-to-the-top-menu-setting/80074/2 "2018-02-08T02:25:20Z")

</div>

We need to hide this setting entirely, it has caused way too many problems.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [2018 年 2 月 8 日午前 2:44 UTC](https://meta.discourse.org/t/invalid-items-can-be-added-to-the-top-menu-setting/80074/3 "2018-02-08T02:44:22Z")

</div>

Couldn’t we just restrict what can be added to the top\_menu to a list of valid items?

---

<div class="post-metadata">

### Author: ![Noah751](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/noah751/32/82274_2.png) [@Noah751](https://meta.discourse.org/u/Noah751)
#### Post date: [2018 年 2 月 8 日午前 3:07 UTC](https://meta.discourse.org/t/invalid-items-can-be-added-to-the-top-menu-setting/80074/4 "2018-02-08T03:07:04Z")

</div>

> [@codinghorror](#):
>
> it has caused way too many problems.

Exactly what problems has it given people, I wouldn’t think someone would intentionally place invalid items on this menu, knowing that it would break their site, it says in the description of what to place. I still have this setting on my community, I have no problems with it.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [2018 年 2 月 8 日午後 6:17 UTC](https://meta.discourse.org/t/invalid-items-can-be-added-to-the-top-menu-setting/80074/5 "2018-02-08T18:17:01Z")

</div>

What can go wrong is that a non-existent page can be set as the Discourse homepage. In the example I gave above, Discourse would be trying to find `/foobar` for the site’s homepage. It wouldn’t be possible to remove `foobar` from the top menu items, because on refreshing the settings page, ‘foobar’ would not be displayed as a top menu item, but `foobar` would still be stored internally by Discourse as the first item in the top menu list.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2018 年 2 月 8 日午後 7:00 UTC](https://meta.discourse.org/t/invalid-items-can-be-added-to-the-top-menu-setting/80074/6 "2018-02-08T19:00:04Z")

</div>

We could and we should, we also should have app safe guards that ensure that this kind of breakage is not possible.

I am fine with nuking this, but we will still need a drop down to select home page, and then people would need a theme component to fuss with top menu.

Easiest thing here is just to remove all the voodoo from that site setting, only allow people to pick from a fixed list and reorganize

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2018 年 2 月 9 日午前 12:41 UTC](https://meta.discourse.org/t/invalid-items-can-be-added-to-the-top-menu-setting/80074/7 "2018-02-09T00:41:14Z")

</div>

> [@sam](#):
>
> but we will still need a drop down to select home page

WE ALREADY HAVE THIS, it’s called the setup wizard. So frustrated that I have to keep pointing this out over and over..

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2018 年 2 月 9 日午前 1:40 UTC](https://meta.discourse.org/t/invalid-items-can-be-added-to-the-top-menu-setting/80074/8 "2018-02-09T01:40:00Z")

</div>

That is a small percent of what that setting does though, it lets you add “read” “posted” or “bookmarks” and reorganize tabs.

Wizard lets you pick homepage (between latest and categories) it omits “top” as an option which is probably a legit homepage in some cases.

I am adding to my list to kill all the support pain around this which has existed for many years. (and a few other settings that also share pain with this)

1. Very oddly, we don’t appear to have a proper validator for site settings that ensures a string must match a regex. We have one for string must include regex which is very different. I need this cause the regex will be `^(latest|categories|top)` combined with (2), allowing `unread` and others to be home page causes support issues, they can do that in a plugin.

2. We don’t appear to have a setting on “list” that ensures you can not add “free form” text to the selections, this is really bad cause post\_menu also would use it so you don’t add bogus stuff to post\_menu.

3. The help text is not great

I agree we have suffered here with this setting and post\_menu to a degree and want to at least remove this suffering.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2018 年 4 月 26 日午前 7:04 UTC](https://meta.discourse.org/t/invalid-items-can-be-added-to-the-top-menu-setting/80074/9 "2018-04-26T07:04:56Z")

</div>

I am mostly done here but kind of want to hand this over to @j.jaffeux to finish some stuff up here:

 ![image](https://global.discourse-cdn.com/meta/original/3X/b/7/b77e1892622acec08e3c2ce6b99031b5878dcc10.png)

Per:

[https://github.com/discourse/discourse/commit/88f5251415650f875817c3b3d4a73987a6cd270a](https://github.com/discourse/discourse/commit/88f5251415650f875817c3b3d4a73987a6cd270a)

We have an extra `allow_any` attribute for site setting (default is true). If `allow_any` is set to `false` on a list, the choices are restricted so they always match the list.

So for this case, top\_menu is now restricted to any combination of:

```plaintext
choices:
     - latest
     - new
     - unread
     - top
     - categories
     - read
     - posted
     - bookmarks

```

But… the control used in the UX is now an ugly text box. Since this is a site setting we can live with this, but it is visually somewhat ugly.

That said, you can no longer shoot yourself in foot, which is great.

This commit totally kills 2 features as well:

1. You can not longer “magic” a category into top menu which we used to support, this has to be done in a theme.

2. You can not longer use the “magic” `-` thingy to remove categories from lists, instead you set it in category settings.

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [2018 年 4 月 28 日午前 10:33 UTC](https://meta.discourse.org/t/invalid-items-can-be-added-to-the-top-menu-setting/80074/10 "2018-04-28T10:33:12Z")

</div>

> [@sam](#):
>
> You can not longer “magic” a category into top menu which we used to support, this has to be done in a theme.

Is there a #howto for that? I thought I saw one, but my 🔍 skills didn’t suffice to dig it out again – or it never existed and I just hallucinated 🤪

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2018 年 4 月 30 日午前 8:13 UTC](https://meta.discourse.org/t/invalid-items-can-be-added-to-the-top-menu-setting/80074/11 "2018-04-30T08:13:41Z")

</div>

This topic was automatically closed after 4 days. New replies are no longer allowed.
