[2.x] Tags: one way for extensions to tell primary from secondary tags

Open
#5,455 0 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

@Saksham-chourasia is already working on this.

Since Nov 13, 2026.

  • #5504 by @Saksham-chourasia — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Active
Domain
api, backend, frontend

Research direction

Start with the backend and frontend Tag models, then trace the position checks named in the tags extension: GlobalPolicy, DiscussionResourceFields, Content\Tags, the admin and forum Tags pages, addTagList, addTagComposer, TagSelectionModal, and sortTags. Compare their existing checks with is_primary and the stated counting rules; the issue lists the required helpers, query scopes, compatibility behavior, and documentation updates. Done when these checks use the helpers, secondary tag positions remain null in 2.x, and the deprecation is documented.

Written by the indexing model from the issue text.

Description

needs-discussion type/feature

Extensions, and the tags extension itself, decide whether a tag is primary by checking position: a secondary tag has none. That ties the tag's kind to its order, which stops secondary tags from ever being ordered (#5236), and the check is repeated in about ten places, with small differences.

Tags already store the kind in is_primary, exposed as isPrimary in the API and Tag.isPrimary() in JS. A child of a primary tag is a primary tag: is_primary is true for it, as it is for its parent.

Proposal

On the backend Tag model and the frontend Tag model:

  • isPrimary(): a primary tag or a child of one, read from is_primary.
  • isChild(): a child of a primary tag.
  • isPrimaryParent(): a primary tag without a parent (frontend already has it).
  • isSecondary(): !isPrimary().
  • Backend query scopes Tag::query()->primary() and ->secondary().

Then:

  • Move every check in the tags extension from position to these: GlobalPolicy, DiscussionResourceFields, Content\Tags, the admin and forum Tags pages, addTagList, addTagComposer, TagSelectionModal and sortTags.
  • Keep position null for secondary tags in 2.x, so extensions that check it keep working, and mark that check deprecated in the changelog and the extension docs.
  • The required tag counts keep their behaviour: top-level primary tags count as primary, every other tag (children included) towards the secondary limits. Name it that way in code and docs rather than calling children secondary.

This depends on repairing is_primary: the admin edit modal currently clears it when saving an existing tag. That repair is included in the work on #5236.

The permission mismatch and child-tag counting discussion already have #4065 and #3640; this proposal supplies consistent helpers without deciding a new counting policy.

Dominant language
PHP
Stars
6.8k
Forks
891
Avg merge
1d 10h
Merged PRs (30d)
209

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from flarum/framework

All issues in flarum/framework

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.