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
8 changed files with 7 additions and 82 deletions
@@ -3,7 +3,7 @@
; License GNU General Public License version 3 or later; see LICENSE
; Note: All ini files need to be saved as UTF-8
PLG_SYSTEM_MOKOJOOMTOS="System - MokoJoomTOS"
PLG_SYSTEM_MOKOJOOMTOS="System - Offline Terms of Service"
PLG_SYSTEM_MOKOJOOMTOS_XML_DESCRIPTION="Allows Terms of Service to be accessible via menu slug when the site is in offline mode. Simply configure the menu slug (e.g., 'terms-of-service') and that page will remain accessible even when the site is offline."
; Configuration
@@ -3,5 +3,5 @@
; License GNU General Public License version 3 or later; see LICENSE
; Note: All ini files need to be saved as UTF-8
PLG_SYSTEM_MOKOJOOMTOS="System - MokoJoomTOS"
PLG_SYSTEM_MOKOJOOMTOS="System - Offline Terms of Service"
PLG_SYSTEM_MOKOJOOMTOS_XML_DESCRIPTION="Allows Terms of Service to be accessible via menu slug when site is offline"
@@ -3,7 +3,7 @@
; License GNU General Public License version 3 or later; see LICENSE
; Note: All ini files need to be saved as UTF-8
PLG_SYSTEM_MOKOJOOMTOS="System - MokoJoomTOS"
PLG_SYSTEM_MOKOJOOMTOS="System - Offline Terms of Service"
PLG_SYSTEM_MOKOJOOMTOS_XML_DESCRIPTION="Allows Terms of Service to be accessible via menu slug when the site is in offline mode. Simply configure the menu slug (e.g., 'terms-of-service') and that page will remain accessible even when the site is offline."
; Configuration
@@ -3,5 +3,5 @@
; License GNU General Public License version 3 or later; see LICENSE
; Note: All ini files need to be saved as UTF-8
PLG_SYSTEM_MOKOJOOMTOS="System - MokoJoomTOS"
PLG_SYSTEM_MOKOJOOMTOS="System - Offline Terms of Service"
PLG_SYSTEM_MOKOJOOMTOS_XML_DESCRIPTION="Allows Terms of Service to be accessible via menu slug when site is offline"
@@ -3,7 +3,7 @@
; License GNU General Public License version 3 or later; see LICENSE
; Note: All ini files need to be saved as UTF-8
PLG_SYSTEM_MOKOJOOMTOS="System - MokoJoomTOS"
PLG_SYSTEM_MOKOJOOMTOS="System - Offline Terms of Service"
PLG_SYSTEM_MOKOJOOMTOS_XML_DESCRIPTION="Allows Terms of Service to be accessible via menu slug when the site is in offline mode. Simply configure the menu slug (e.g., 'terms-of-service') and that page will remain accessible even when the site is offline."
; Configuration
@@ -3,7 +3,7 @@
; License GNU General Public License version 3 or later; see LICENSE
; Note: All ini files need to be saved as UTF-8
PLG_SYSTEM_MOKOJOOMTOS="System - MokoJoomTOS"
PLG_SYSTEM_MOKOJOOMTOS="System - Offline Terms of Service"
PLG_SYSTEM_MOKOJOOMTOS_XML_DESCRIPTION="Allows Terms of Service to be accessible via menu slug when the site is in offline mode. Simply configure the menu slug (e.g., 'terms-of-service') and that page will remain accessible even when the site is offline."
; Configuration
+1 -2
View File
@@ -13,7 +13,6 @@ defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Field\ListField;
use Joomla\CMS\Language\Text;
use Joomla\Plugin\System\MokoJoomTOS\Utility\PrettyName;
/**
* Menu Slug Field
@@ -78,7 +77,7 @@ class MenuslugField extends ListField
$lastMenuType = $item->menutype;
}
$displayText = $item->title !== '' ? $item->title : PrettyName::fromSlug($item->alias);
$displayText = $item->title !== '' ? $item->title : ucwords(str_replace(['-', '_'], ' ', $item->alias));
$options[] = (object) [
'value' => $item->alias,
'text' => $displayText . ' (' . $item->alias . ')'
1
-74
View File
@@ -1,74 +0,0 @@
<?php
/**
* @package MokoJoomTOS
* @subpackage plg_system_mokojoomtos
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
* @license GNU General Public License version 3 or later; see LICENSE
*/
namespace Joomla\Plugin\System\MokoJoomTOS\Utility;
defined('_JEXEC') or die;
/**
* PrettyName Utility
*
* Provides helpers for generating human-readable display names from slugs
* and other machine-friendly string formats.
*
* @since 03.08.05
*/
final class PrettyName
{
/**
* Words that are kept lowercase in title case unless they are the first word.
*
* @var string[]
* @since 03.08.05
*/
private const LOWERCASE_WORDS = [
'a', 'an', 'and', 'as', 'at', 'but', 'by', 'for',
'if', 'in', 'nor', 'of', 'on', 'or', 'so', 'the',
'to', 'up', 'via', 'yet',
];
/**
* Generate a human-readable display name from a slug.
*
* Converts hyphenated or underscored slugs to title-cased words,
* keeping common short words (articles, conjunctions, prepositions)
* in lowercase unless they appear as the first word.
* For example: 'terms-of-service' becomes 'Terms of Service'.
*
* @param string $slug The slug to convert (e.g., 'terms-of-service').
*
* @return string The pretty display name (e.g., 'Terms of Service').
*
* @since 03.08.05
*/
public static function fromSlug(string $slug): string
{
if (empty($slug))
{
return '';
}
$words = explode(' ', str_replace(['-', '_'], ' ', $slug));
foreach ($words as $index => &$word)
{
$lower = strtolower($word);
if ($index === 0 || !\in_array($lower, self::LOWERCASE_WORDS, true))
{
$word = ucfirst($lower);
}
else
{
$word = $lower;
}
}
return implode(' ', $words);
}
}