|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MedianetDev\BackpackForm\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
|
6
|
|
|
use Illuminate\Console\Command; |
|
7
|
|
|
use Illuminate\Support\Facades\Artisan; |
|
8
|
|
|
use Illuminate\Support\Facades\File; |
|
9
|
|
|
|
|
10
|
|
|
class InitBackpackFormInstallation extends Command |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* The name and signature of the console command. |
|
14
|
|
|
* |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $signature = 'backpack-form:installation'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* The console command description. |
|
21
|
|
|
* |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $description = 'Script call after installation via composer'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Execute the console command. |
|
28
|
|
|
* |
|
29
|
|
|
* @return mixed |
|
30
|
|
|
*/ |
|
31
|
|
|
public function handle() |
|
32
|
|
|
{ |
|
33
|
|
|
$name = __('medianet-dev.backpack-form::formbuilder.labels.entity'); |
|
34
|
|
|
$nameTitle = ucfirst(Str::camel($name)); |
|
|
|
|
|
|
35
|
|
|
$nameKebab = 'formbuilder'; |
|
36
|
|
|
$namePlural = ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.entities_form')); |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
$this->call('migrate'); |
|
39
|
|
|
|
|
40
|
|
|
$this->call('vendor:publish', [ |
|
41
|
|
|
'--provider' => "MedianetDev\BackpackForm\AddonServiceProvider", |
|
42
|
|
|
'--tag' => "config" |
|
43
|
|
|
]); |
|
44
|
|
|
$this->call('vendor:publish', [ |
|
45
|
|
|
'--provider' => "MedianetDev\BackpackForm\AddonServiceProvider", |
|
46
|
|
|
'--tag' => "assets" |
|
47
|
|
|
]); |
|
48
|
|
|
|
|
49
|
|
|
$this->call('vendor:publish', [ |
|
50
|
|
|
'--provider' => "MedianetDev\BackpackForm\AddonServiceProvider", |
|
51
|
|
|
'--tag' => "views" |
|
52
|
|
|
]); |
|
53
|
|
|
|
|
54
|
|
|
// Check if sidebar item already exists before adding it |
|
55
|
|
|
$this->addSidebarItemIfNotExists($nameKebab); |
|
56
|
|
|
|
|
57
|
|
|
// if the application uses cached routes, we should rebuild the cache so the previous added route will |
|
58
|
|
|
// be acessible without manually clearing the route cache. |
|
59
|
|
|
if (app()->routesAreCached()) { |
|
|
|
|
|
|
60
|
|
|
$this->call('route:cache'); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Add the sidebar item only if it doesn't already exist in the sidebar_content file |
|
66
|
|
|
* |
|
67
|
|
|
* @param string $nameKebab |
|
68
|
|
|
* @return void |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function addSidebarItemIfNotExists($nameKebab) |
|
71
|
|
|
{ |
|
72
|
|
|
// Path to the Backpack sidebar_content file |
|
73
|
|
|
$sidebarPath = resource_path('views/vendor/backpack/base/inc/sidebar_content.blade.php'); |
|
74
|
|
|
|
|
75
|
|
|
// Check if the sidebar content file exists |
|
76
|
|
|
if (!File::exists($sidebarPath)) { |
|
77
|
|
|
$this->warn('Sidebar content file not found. Creating sidebar item anyway.'); |
|
78
|
|
|
$this->addSidebarItem($nameKebab); |
|
79
|
|
|
return; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
// Get the content of the sidebar file |
|
83
|
|
|
$sidebarContent = File::get($sidebarPath); |
|
84
|
|
|
|
|
85
|
|
|
// Check if the sidebar already contains a link to the formbuilder |
|
86
|
|
|
if (Str::contains($sidebarContent, "backpack_url('$nameKebab')") || |
|
87
|
|
|
Str::contains($sidebarContent, "{{ __('sidebar.forms_list') }}")) { |
|
88
|
|
|
$this->info('Formbuilder sidebar item already exists. Skipping.'); |
|
89
|
|
|
} else { |
|
90
|
|
|
$this->info('Adding Formbuilder sidebar item.'); |
|
91
|
|
|
$this->addSidebarItem($nameKebab); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Add the sidebar item |
|
97
|
|
|
* |
|
98
|
|
|
* @param string $nameKebab |
|
99
|
|
|
* @return void |
|
100
|
|
|
*/ |
|
101
|
|
|
protected function addSidebarItem($nameKebab) |
|
102
|
|
|
{ |
|
103
|
|
|
$this->call('backpack:add-sidebar-content', [ |
|
104
|
|
|
'code' => " |
|
105
|
|
|
@canany(['create_form', 'list_form', 'update_form', 'delete_form']) |
|
106
|
|
|
<li class='nav-item'> |
|
107
|
|
|
<a class='nav-link' href='{{ backpack_url('$nameKebab') }}'> |
|
108
|
|
|
<i class='nav-icon la la-database'></i> |
|
109
|
|
|
{{ __('sidebar.forms_list') }} |
|
110
|
|
|
</a> |
|
111
|
|
|
</li> |
|
112
|
|
|
@endcanany |
|
113
|
|
|
", |
|
114
|
|
|
]); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|