-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathFieldServiceProvider.php
More file actions
79 lines (65 loc) · 1.9 KB
/
Copy pathFieldServiceProvider.php
File metadata and controls
79 lines (65 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace Manogi\Tiptap;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
use Laravel\Nova\Events\ServingNova;
use Laravel\Nova\Nova;
class FieldServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
$this->loadJsonTranslationsFrom(__DIR__.'/../resources/lang');
Nova::serving(function (ServingNova $event) {
// Register routes inside Nova::serving to ensure Nova's middleware
// aliases are registered before we reference them
$this->routes();
Nova::provideToScript([
'tiptapTranslations' => $this->translations(),
]);
Nova::script('tiptap', __DIR__.'/../dist/js/field.js');
Nova::style('tiptap', __DIR__.'/../dist/css/tiptap.css');
});
}
/**
* Register routes.
*
* @return void
*/
protected function routes()
{
if ($this->app->routesAreCached()) {
return;
}
Route::middleware(['nova'])
->prefix('nova-tiptap/api')
->group(__DIR__.'/../routes/api.php');
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->bind('tiptap-content-blocks', function () {
return new TiptapContentBlocks();
});
}
private function translations()
{
$file = resource_path('lang/vendor/nova-tiptap/'.app()->getLocale().'.json');
if (! is_readable($file)) {
$file = base_path('vendor/manogi/nova-tiptap/resources/lang/'.app()->getLocale().'.json');
}
if (is_readable($file)) {
$json = json_decode(file_get_contents($file));
return is_object($json) ? $json : [];
}
return [];
}
}