refactor: remove PrettyName class, inline slug-to-label conversion #5

Merged
Copilot merged 3 commits from copilot/create-pretty-plugin-name into main 2026-03-06 08:38:58 +00:00
Copilot commented 2026-03-06 08:15:10 +00:00 (Migrated from github.com)

PrettyName was a dedicated utility class whose sole purpose was converting hyphenated slugs to display names — overkill for a single call site. Removes the class entirely and replaces it with a two-function inline expression.

Changes

  • Deleted src/src/Utility/PrettyName.php and the Utility/ directory
  • MenuslugField.php — removed use PrettyName import; replaced call with:
// Before
$displayText = $item->title !== '' ? $item->title : PrettyName::fromSlug($item->alias);

// After
$displayText = $item->title !== '' ? $item->title : ucwords(str_replace(['-', '_'], ' ', $item->alias));

Note: ucwords capitalises every word (Terms Of Service) rather than applying title-case rules (Terms of Service). This is intentional — the fallback only fires for untitled menu items, and simple capitalisation is sufficient.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

`PrettyName` was a dedicated utility class whose sole purpose was converting hyphenated slugs to display names — overkill for a single call site. Removes the class entirely and replaces it with a two-function inline expression. ## Changes - **Deleted** `src/src/Utility/PrettyName.php` and the `Utility/` directory - **`MenuslugField.php`** — removed `use PrettyName` import; replaced call with: ```php // Before $displayText = $item->title !== '' ? $item->title : PrettyName::fromSlug($item->alias); // After $displayText = $item->title !== '' ? $item->title : ucwords(str_replace(['-', '_'], ' ', $item->alias)); ``` > Note: `ucwords` capitalises every word (`Terms Of Service`) rather than applying title-case rules (`Terms of Service`). This is intentional — the fallback only fires for untitled menu items, and simple capitalisation is sufficient. <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).
copilot-pull-request-reviewer[bot] (Migrated from github.com) reviewed 2026-03-06 08:41:48 +00:00
copilot-pull-request-reviewer[bot] (Migrated from github.com) left a comment

Pull request overview

This PR simplifies the plugin by removing the dedicated PrettyName utility and inlining the slug-to-label fallback used when menu items have no title. It also updates the displayed plugin name across language packs.

Changes:

  • Deleted PrettyName utility class and removed the Utility/ directory.
  • Inlined slug-to-label conversion in MenuslugField using str_replace() + ucwords().
  • Updated PLG_SYSTEM_MOKOJOOMTOS display name in site/admin language .ini files (en-GB/en-US).

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/src/Utility/PrettyName.php Removed no-longer-needed slug prettification utility class.
src/src/Field/MenuslugField.php Replaced PrettyName::fromSlug() with inline fallback formatting for untitled menu items.
src/language/en-US/plg_system_mokojoomtos.ini Updated plugin display name string.
src/language/en-GB/plg_system_mokojoomtos.ini Updated plugin display name string.
src/administrator/language/en-US/plg_system_mokojoomtos.sys.ini Updated plugin display name string (Extension Manager context).
src/administrator/language/en-US/plg_system_mokojoomtos.ini Updated plugin display name string.
src/administrator/language/en-GB/plg_system_mokojoomtos.sys.ini Updated plugin display name string (Extension Manager context).
src/administrator/language/en-GB/plg_system_mokojoomtos.ini Updated plugin display name string.
## Pull request overview This PR simplifies the plugin by removing the dedicated `PrettyName` utility and inlining the slug-to-label fallback used when menu items have no title. It also updates the displayed plugin name across language packs. **Changes:** - Deleted `PrettyName` utility class and removed the `Utility/` directory. - Inlined slug-to-label conversion in `MenuslugField` using `str_replace()` + `ucwords()`. - Updated `PLG_SYSTEM_MOKOJOOMTOS` display name in site/admin language `.ini` files (en-GB/en-US). ### Reviewed changes Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment. <details> <summary>Show a summary per file</summary> | File | Description | | ---- | ----------- | | src/src/Utility/PrettyName.php | Removed no-longer-needed slug prettification utility class. | | src/src/Field/MenuslugField.php | Replaced `PrettyName::fromSlug()` with inline fallback formatting for untitled menu items. | | src/language/en-US/plg_system_mokojoomtos.ini | Updated plugin display name string. | | src/language/en-GB/plg_system_mokojoomtos.ini | Updated plugin display name string. | | src/administrator/language/en-US/plg_system_mokojoomtos.sys.ini | Updated plugin display name string (Extension Manager context). | | src/administrator/language/en-US/plg_system_mokojoomtos.ini | Updated plugin display name string. | | src/administrator/language/en-GB/plg_system_mokojoomtos.sys.ini | Updated plugin display name string (Extension Manager context). | | src/administrator/language/en-GB/plg_system_mokojoomtos.ini | Updated plugin display name string. | </details>
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2026-03-06 08:41:47 +00:00

The new fallback formatting no longer normalizes the alias to lowercase before applying ucwords(). If a menu alias contains uppercase characters (e.g., created via API/DB import), this can yield odd output like TERMS OF Service compared to the previous PrettyName::fromSlug() behavior. Consider applying strtolower() to the alias before ucwords() to keep output predictable.

                    $displayText = $item->title !== '' ? $item->title : ucwords(str_replace(['-', '_'], ' ', strtolower($item->alias)));
The new fallback formatting no longer normalizes the alias to lowercase before applying `ucwords()`. If a menu alias contains uppercase characters (e.g., created via API/DB import), this can yield odd output like `TERMS OF Service` compared to the previous `PrettyName::fromSlug()` behavior. Consider applying `strtolower()` to the alias before `ucwords()` to keep output predictable. ```suggestion $displayText = $item->title !== '' ? $item->title : ucwords(str_replace(['-', '_'], ' ', strtolower($item->alias))); ```
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: MokoConsulting/MokoJoomTOS#5