Skip to content

Commit 9c2d02a

Browse files
scott graysonscott grayson
authored andcommitted
refactor: Enforce non-empty slugs and change guest plugin default
- Add validation to prevent empty slugs in plugins and resources - Change guest plugin default slug from empty string to 'help' - Update README to remove empty slug documentation - All slugs must now be non-empty strings
1 parent 181d0ae commit 9c2d02a

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,26 +90,25 @@ public function panel(Panel $panel): Panel
9090
{
9191
return $panel
9292
->id('guest')
93-
->path('help') // Panel path
93+
->path('') // Panel path (empty = root, or set to your desired base path)
9494
// ... other panel configuration
9595
// Note: Do NOT add authMiddleware() for guest access
9696
->plugins([
97-
FilamentHelpGuestPlugin::make()
98-
->slug(''), // Optional: customize the URL slug (empty = use panel path)
99-
//...
97+
FilamentHelpGuestPlugin::make(),
98+
// Default slug is 'help', so articles will be at /help (or {panel-path}/help)
99+
// Customize with ->slug('custom-slug') if needed
100100
]);
101101
}
102102
```
103103

104104
**Configuration Options:**
105-
- **Plugin method**: `->slug('custom-slug')` - Set the URL slug when registering the plugin (defaults to empty string `''` if not specified, which uses the panel path directly)
105+
- **Plugin method**: `->slug('custom-slug')` - Set the URL slug when registering the plugin (defaults to `'help'` if not specified)
106+
- **Slug requirement**: Slug must be a non-empty string
106107

107-
**Location**: Guest panel (defaults to panel path, configurable via `->slug()`)
108+
**Location**: Guest panel (defaults to `{panel-path}/help`, configurable via `->slug()`)
108109
**Access**: Public (no authentication required)
109110
**Features**: Read-only access to public help articles for guests
110111

111-
**Note**: If you don't specify a slug (or pass an empty string), the help articles will be available directly at the panel path. For example, if your panel path is `help`, articles will be at `/help` and `/help/{slug}`.
112-
113112
## Help Article Locations
114113

115114
Help articles are available in three different locations depending on your setup:

src/FilamentHelpFrontendPlugin.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public function register(Panel $panel): void
3232
$defaultSlug = 'help';
3333
$slug = $this->slug ?? $defaultSlug;
3434

35+
if (empty($slug)) {
36+
throw new \InvalidArgumentException('Slug cannot be empty. Please provide a non-empty slug when registering the plugin.');
37+
}
38+
3539
\Tapp\FilamentHelp\Resources\Frontend\HelpArticleResource::setSlug($slug);
3640

3741
$panel

src/FilamentHelpGuestPlugin.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@ public function getId(): string
2828

2929
public function register(Panel $panel): void
3030
{
31-
// Set the slug on the resource - use provided slug or default to empty string (uses panel path)
32-
$defaultSlug = ''; // Empty string means use panel path directly
31+
// Set the slug on the resource - use provided slug or default to 'help'
32+
$defaultSlug = 'help';
3333
$slug = $this->slug ?? $defaultSlug;
3434

35+
if (empty($slug)) {
36+
throw new \InvalidArgumentException('Slug cannot be empty. Please provide a non-empty slug when registering the plugin.');
37+
}
38+
3539
\Tapp\FilamentHelp\Resources\Guest\HelpArticleResource::setSlug($slug);
3640

3741
$panel

src/Resources/Frontend/HelpArticleResource.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public static function shouldRegisterNavigation(): bool
3131

3232
public static function setSlug(string $slug): void
3333
{
34+
if (empty($slug)) {
35+
throw new \InvalidArgumentException('Slug cannot be empty.');
36+
}
37+
3438
static::$slug = $slug;
3539
}
3640

src/Resources/Guest/HelpArticleResource.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ public static function shouldRegisterNavigation(): bool
2727

2828
protected static ?string $modelLabel = 'Help Article';
2929

30-
protected static string $slug = '';
30+
protected static string $slug = 'help';
3131

3232
public static function setSlug(string $slug): void
3333
{
34+
if (empty($slug)) {
35+
throw new \InvalidArgumentException('Slug cannot be empty.');
36+
}
37+
3438
static::$slug = $slug;
3539
}
3640

0 commit comments

Comments
 (0)