Skip to content

Commit 55ad8c1

Browse files
committed
Add the possibility to add a custom sentence to the footer instead the configured app name
- Add the possibility of adding a custom sentence to the footer instead the configured app name - Updating PHPDocs - Adding some tests - Update the readme
1 parent c55ab70 commit 55ad8c1

File tree

5 files changed

+113
-1
lines changed

5 files changed

+113
-1
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ This filament Plugin provides an easy and flexible way to add a customizable foo
2020
- [Usage](#usage)
2121
- [Configurations](#configurations)
2222
- [Footer position](#footer-position)
23+
- [Custom sentence](#custom-sentence)
2324
- [Show GitHub version](#show-github-version)
2425
- [Show load time](#load-time)
2526
- [Custom logo with link](#custom-logo-with-link)
@@ -135,6 +136,37 @@ use Devonab\FilamentEasyFooter\EasyFooterPlugin;
135136
```
136137
![Filament Easy Footer sidebar footer position](./art/position_sidebar_footer.webp)
137138

139+
### Custom sentence
140+
![Filament Easy Footer custom sentence](./art/custom_sentence.webp)
141+
142+
By default, the plugin will display the name of your application (configured from your .ENV) next to the copyright. You can change the phrase by publishing the plugin configuration file.
143+
144+
If you prefer a more personalized approach, you can use the following method:
145+
146+
```php
147+
use Devonab\FilamentEasyFooter\EasyFooterPlugin;
148+
149+
->plugins([
150+
EasyFooterPlugin::make()
151+
->withSentence('your sentence'),
152+
])
153+
```
154+
155+
The method accepts a string or HTMLString as a parameter.
156+
With this, you can get the result you want. For example, for the result shown in the image above :
157+
158+
```php
159+
use Devonab\FilamentEasyFooter\EasyFooterPlugin;
160+
161+
->plugins([
162+
EasyFooterPlugin::make()
163+
->withSentence(new HtmlString('<img src="https://static.cdnlogo.com/logos/l/23/laravel.svg" style="margin-right:.5rem;" alt="Laravel Logo" width="20" height="20"> Laravel'))
164+
,
165+
])
166+
```
167+
The authorized tags are as follows: `<strong><img><em><span><b><i><small>`.
168+
169+
138170
### Show GitHub version
139171
![Filament Easy Footer github](./art/github_version.webp)
140172

art/custom_sentence.webp

2.51 KB
Loading

resources/views/easy-footer.blade.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,17 @@
3535
} => $footerPosition === 'footer',
3636
])
3737
>
38-
<span>&copy; {{ now()->format('Y') }} - {{ config('filament-easy-footer.app_name') }}</span>
38+
<span @class(['flex gap-2' => $isHtmlSentence])>&copy; {{ now()->format('Y') }} -
39+
@if($sentence)
40+
@if($isHtmlSentence)
41+
<span class="flex">{!! $sentence !!}</span>
42+
@else
43+
{{ $sentence }}
44+
@endif
45+
@else
46+
{{ config('filament-easy-footer.app_name') }}
47+
@endif
48+
</span>
3949

4050
@if($githubEnabled)
4151
<livewire:devonab.filament-easy-footer.github-version

src/EasyFooterPlugin.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Devonab\FilamentEasyFooter\Services\GitHubService;
66
use Filament\Contracts\Plugin;
77
use Filament\Panel;
8+
use Illuminate\Support\HtmlString;
89

910
class EasyFooterPlugin implements Plugin
1011
{
@@ -26,6 +27,9 @@ class EasyFooterPlugin implements Plugin
2627

2728
protected ?string $loadTimePrefix = null;
2829

30+
protected ?string $sentence = null;
31+
protected bool $isHtmlSentence = false;
32+
2933
protected string $footerPosition = 'footer';
3034

3135
protected array $links = [];
@@ -98,6 +102,8 @@ protected function renderFooter(float $startTime): string
98102
'loadTime' => $this->loadTimeEnabled ? $this->calculateLoadTime($startTime) : false,
99103
'loadTimePrefix' => $this->loadTimePrefix,
100104
'links' => $this->links,
105+
'sentence' => $this->sentence,
106+
'isHtmlSentence' => $this->isHtmlSentence
101107
])->render();
102108
}
103109

@@ -227,6 +233,24 @@ public function withLogo(string $path, ?string $url = null, int $height = 20): s
227233
return $this;
228234
}
229235

236+
/**
237+
* Set a custom sentence that replaces the app name in the copyright text
238+
* Only allows basic HTML tags for text formatting
239+
*
240+
* @param string|HtmlString $sentence Custom text or HTML to display
241+
* @return static
242+
*/
243+
public function withSentence(string|HtmlString $sentence): static
244+
{
245+
if ($sentence instanceof HtmlString) {
246+
$sentence = $sentence->toHtml();
247+
$this->isHtmlSentence = true;
248+
}
249+
250+
$this->sentence = strip_tags($sentence, '<strong><img><em><span><b><i><small>');
251+
return $this;
252+
}
253+
230254
/**
231255
* Check if load time is enabled
232256
*/
@@ -275,6 +299,24 @@ public function getLogoHeight(): int
275299
return $this->logoHeight;
276300
}
277301

302+
/**
303+
* Get the current sentence
304+
* @return string|null
305+
*/
306+
public function getSentence(): ?string
307+
{
308+
return $this->sentence;
309+
}
310+
311+
/**
312+
* Check if the sentence is HTML
313+
* @return bool
314+
*/
315+
public function isHtmlSentence(): bool
316+
{
317+
return $this->isHtmlSentence;
318+
}
319+
278320
/**
279321
* Boot the plugin
280322
*/

tests/Feature/FilamentPluginTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use Devonab\FilamentEasyFooter\EasyFooterPlugin;
44
use Illuminate\Http\Request;
5+
use Illuminate\Support\HtmlString;
56

67
it('has correct plugin ID')
78
->expect(fn () => EasyFooterPlugin::make()->getId())
@@ -105,6 +106,33 @@
105106
]);
106107
});
107108

109+
it('can set plain text sentence', function () {
110+
$plugin = EasyFooterPlugin::make()
111+
->withSentence('Custom Footer Text');
112+
113+
expect($plugin->getSentence())->toBe('Custom Footer Text');
114+
});
115+
116+
it('allows safe HTML tags', function () {
117+
$plugin = EasyFooterPlugin::make()
118+
->withSentence(new HtmlString('<strong>Custom</strong> <em>Footer</em> Text'));
119+
120+
expect($plugin->getSentence())->toBe('<strong>Custom</strong> <em>Footer</em> Text');
121+
});
122+
123+
it('strips unsafe HTML tags but keeps content', function () {
124+
$plugin = EasyFooterPlugin::make()
125+
->withSentence(new HtmlString('<script>alert("I\'m a hacker yiek yiek")</script><strong>Safe</strong>'));
126+
127+
expect($plugin->getSentence())->toBe('alert("I\'m a hacker yiek yiek")<strong>Safe</strong>');
128+
});
129+
130+
it('defaults to null sentence', function () {
131+
$plugin = EasyFooterPlugin::make();
132+
133+
expect($plugin->getSentence())->toBeNull();
134+
});
135+
108136
test('make creates new instance')
109137
->expect(fn () => EasyFooterPlugin::make())
110138
->toBeInstanceOf(EasyFooterPlugin::class);

0 commit comments

Comments
 (0)