Skip to content

Commit 4eb751d

Browse files
authored
Merge pull request #65 from QuentinGab/master
Add usable translations for the notification and fix readme
2 parents e50f992 + a7921d4 commit 4eb751d

File tree

4 files changed

+70
-8
lines changed

4 files changed

+70
-8
lines changed

README.md

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,51 @@ When the user clicks the download link in the mail that gets sent after creating
203203

204204
If you don't want to enforce that a user should be logged in to able to download a personal data export, you can set the `authentication_required` config value to `false`. Setting the value to `false` is less secure because anybody with a link to a zip file will be able to download it, but because the name of the zip file contains many random characters, it will be hard to guess it.
205205

206+
### Translate the mail
207+
208+
You need to publish the translations:
209+
210+
```bash
211+
php artisan vendor:publish --provider="Spatie\PersonalDataExport\PersonalDataExportServiceProvider" --tag="translations"
212+
```
213+
206214
### Customizing the mail
207215

208-
You can customize the mailable itself by creating your own mailable that extends `\Spatie\PersonalDataExport\Mail\PersonalDataExportCreatedMail` and register the class name of your mailable in the `mailable` config key of `config/personal-data-export.php`.
216+
You can customize the mailable itself by creating your own mailable that extends `Spatie\PersonalDataExport\Notifications\PersonalDataExportedNotification` and register the class name of your mailable in the `mailable` config key of `config/personal-data-export.php`.
217+
218+
Here is an example:
219+
220+
```php
221+
use Spatie\PersonalDataExport\Notifications\PersonalDataExportedNotification as SpatiePersonalDataExportedNotification;
222+
class PersonalDataExportedNotification extends SpatiePersonalDataExportedNotification
223+
{
224+
public function via($notifiable)
225+
{
226+
return ['mail'];
227+
}
228+
public function toMail($notifiable)
229+
{
230+
$downloadUrl = route('personal-data-exports', $this->zipFilename);
231+
if (static::$toMailCallback) {
232+
return call_user_func(static::$toMailCallback, $notifiable, $downloadUrl);
233+
}
234+
return (new MailMessage)
235+
->subject(trans('personal-data-exports.notifications.subject'))
236+
->line(trans('personal-data-exports.notifications.instructions'))
237+
->action(trans('personal-data-exports.notifications.action'), $downloadUrl)
238+
->line(trans('personal-data-exports.notifications.deletion_message', ['date' => $this->deletionDatetime->format('Y-m-d H:i:s')]));
239+
}
240+
}
241+
```
242+
243+
Then register the class name of your mailable in the `mailable` config key of `config/personal-data-export.php`
244+
245+
```php
246+
/*
247+
* Something like that
248+
*/
249+
'notification' => \App\Notifications\PersonalDataExportedNotification::class,
250+
```
209251

210252
### Customizing the queue
211253

@@ -273,4 +315,4 @@ If you discover any security related issues, please email freek@spatie.be instea
273315

274316
## License
275317

276-
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
318+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

resources/lang/en/notifications.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
return [
4+
'subject' => 'Personal Data Download',
5+
'instructions' => 'Please click the button below to download a zip file containg all data we got for your account.',
6+
'action' => 'Download Zip File',
7+
'deletion_message' => 'This file will be deleted at :date.',
8+
];

src/Notifications/PersonalDataExportedNotification.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,13 @@ public function toMail($notifiable)
4242
}
4343

4444
return (new MailMessage)
45-
->subject(Lang::get('Personal Data Download'))
46-
->line(Lang::get('Please click the button below to download a zip file containg all data we got for your account.'))
47-
->action(Lang::get('Download Zip File'), $downloadUrl)
48-
->line(Lang::get('This file will be deleted at ' . $this->deletionDatetime->format('Y-m-d H:i:s') . '.'));
45+
->subject(trans('personal-data-export::notifications.subject'))
46+
->line(trans('personal-data-export::notifications.instructions'))
47+
->action(trans('personal-data-export::notifications.action'), $downloadUrl)
48+
->line(trans(
49+
'personal-data-export::notifications.deletion_message',
50+
['date' => $this->deletionDatetime->format('Y-m-d H:i:s')]
51+
));
4952
}
5053

5154
public static function toMailUsing($callback)

src/PersonalDataExportServiceProvider.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function boot()
1212
{
1313
if ($this->app->runningInConsole()) {
1414
$this->publishes([
15-
__DIR__.'/../config/personal-data-export.php' => config_path('personal-data-export.php'),
15+
__DIR__ . '/../config/personal-data-export.php' => config_path('personal-data-export.php'),
1616
], 'config');
1717
}
1818

@@ -21,13 +21,22 @@ public function boot()
2121
->name('personal-data-exports');
2222
});
2323

24+
$this->loadTranslationsFrom(
25+
__DIR__ . '/../resources/lang/',
26+
"personal-data-export"
27+
);
28+
29+
$this->publishes([
30+
__DIR__ . '/../resources/lang' => resource_path("lang/vendor/personal-data-export"),
31+
], "translations");
32+
2433
$this->commands([
2534
CleanOldPersonalDataExportsCommand::class,
2635
]);
2736
}
2837

2938
public function register()
3039
{
31-
$this->mergeConfigFrom(__DIR__.'/../config/personal-data-export.php', 'personal-data-export');
40+
$this->mergeConfigFrom(__DIR__ . '/../config/personal-data-export.php', 'personal-data-export');
3241
}
3342
}

0 commit comments

Comments
 (0)