addon.doc.home / Sample manual

Addons

Addons live under addons/{name}/. Install detects file conflicts. You can also install from Admin → Addons or the store.

Prefer platform building blocks

Addon code should reuse HareAdmin built-ins instead of bundling parallel stacks. Smaller packages, consistent admin UX, fewer conflicts.

  • Table / form / upload / dialog / toast: use Table.api, Form.api, Fast.api.ajax / confirm / contentDialog, Toastr, Layer.
  • Editor / SMS / payment / storage: register via drivers; consumers only use generic classes (e.g. .editor).
  • Admin page scripts: prefer inline scripts in the view; do not add thin public/assets/js/backend/** wrappers for one list page.
  • Copy: lang() + short reusable keys; content via ContentLang; visitor config via Settings / localize.
  • CSS: AdminLTE4 / Bootstrap 5 + system content CSS; ship only business-critical extras.
  • Introduce third-party libs under addon assets/ only when the platform has no equivalent; register paths in bootstrap.js.

Layout

blog/
├── Blog.php           # main class (install/uninstall/menu/hooks)
├── info.ini
├── config.php         # settings schema
├── bootstrap.js       # optional RequireJS paths
├── install.sql
├── controller/ model/ view/
├── lang/              # merged into yt_lang
├── app/               # overlays project app/
├── public/            # overlays project public/
└── assets/            # copied to public/assets/addons/blog/

Notes

  • assets/ → /public/assets/addons/{name}/; use __ADDON__ in views. Keep it lean.
  • Lang PHP files merge via LangPack::mergeAddon.
  • Register drivers in configInit; consumers use generic classes.

Config / localize

Visitor-facing strings: localize => true in config.php. Read via Settings. Full rules: Internationalization → Settings / localize.

CLI

php think addon -a blog -c create|enable|disable|uninstall|package

Member group capabilities (UserCapability)

Member groups stay a thin core: table user_group, user field group_id, and admin CRUD. Day-to-day ACL is done by toggling capabilities on the group form. The low-level user/rule tree remains for power users and is hidden from the sidebar by default (yetuadmin.member_rule_menu = false; set true to show again).

Do not ship a separate “member group” addon just to own group_id. Business addons register the abilities they need; operators only tick checkboxes.

Register (addons)

In addon configInit or hook user_capability_init:

\app\common\library\UserCapability::register('addon/shop/buy', [
    'title' => 'Shop buy',          // lang key / short English label
    'category' => 'shop',
    'category_title' => 'Shop',
    'priority' => 50,
]);

name must match the full rule path used at check time (same style as historic user_rule.name, e.g. index/user/profile, api/user/login).

Check

Auth::instance()->hasCapability('addon/shop/buy');

Auth::check() still supports module-relative paths for request URI checks. Prefer hasCapability() for registered full capability names (no current-module prefix).

Storage & compatibility

  • Selections are written to user_group.rules as user_rule ids (ancestors included) so existing Auth::check() keeps working.
  • Saving the capability form preserves custom rule nodes that are not in the capability registry (advanced tree edits are not wiped).
  • Core builtins: frontend + API login / register / member center / profile.

Do / Don't

  • Do register capabilities from the addon that enforces them.
  • Do reuse short i18n labels for titles (Login, Profile, …).
  • Don't ask operators to maintain the rule tree for routine ACL.
  • Don't hardcode provider-specific ACL outside the capability + group model.

Dev edition — behavior may still evolve; keep samples copy-paste friendly.