Repository navigation
Expand file tree
/
Copy pathBootstrapBusinessTheme.php
More file actions
127 lines (113 loc) · 4.08 KB
/
Copy pathBootstrapBusinessTheme.php
File metadata and controls
127 lines (113 loc) · 4.08 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
declare(strict_types=1);
namespace Theme\BootstrapBusiness;
use App\Application\Devflow;
use App\Infrastructure\Services\Theme;
use App\Shared\Services\Registry;
use Qubus\EventDispatcher\ActionFilter\Action;
use Qubus\EventDispatcher\ActionFilter\Filter;
use Qubus\Exception\Exception;
use ReflectionException;
use Vihzhuo\Contracts\ThemeContract;
use Vihzhuo\Theme as BuilderTheme;
use function App\Shared\Helpers\compare_releases;
use function App\Shared\Helpers\theme_root;
use function App\Shared\Helpers\theme_url;
use function basename;
use function dirname;
use function get_class;
use function Qubus\Security\Helpers\t__;
class BootstrapBusinessTheme extends Theme
{
/**
* @inheritDoc
* @throws ReflectionException|Exception
*/
public function meta(): array
{
$theme = [
'name' => t__(msgid: 'Bootstrap Business', domain: 'bootstrap-business'),
'id' => 'bootstrap-business',
'slug' => 'BootstrapBusiness',
'author' => 'Joshua Parker',
'version' => '3.0.0',
'description' => t__(
msgid: 'A multipurpose Bootstrap full website template ported from Start Bootstrap.',
domain: 'bootstrap-business'
),
'basename' => basename(dirname(__FILE__)),
'path' => theme_root(__FILE__),
'url' => theme_url('', __CLASS__),
'themeUri' => 'https://github.com/getdevflow/bootstrap-business',
'authorUri' => 'https://joshuaparker.dev/',
'className' => get_class($this),
'screenshot' => theme_url('BootstrapBusiness/images/screenshot.png'),
];
Registry::getInstance()->set('bootstrap-business', $theme);
return $theme;
}
/**
* @inheritDoc
* @throws Exception
* @throws ReflectionException
*/
public function handle(): void
{
if (compare_releases(Devflow::release(), '2.3.0', '<')) {
$this->registerAdminNotice();
return;
}
Filter::getInstance()->addFilter('pagebuilder.support', fn() => true);
// These hooks are inert when Header Footer Builder is not installed/active.
Filter::getInstance()->addFilter(
'header.footer.slots',
[$this, 'headerFooterSlots'],
arguments: 2
);
Filter::getInstance()->addFilter(
'header.footer.canvas.assets',
[$this, 'headerFooterCanvasAssets'],
arguments: 2
);
}
public function headerFooterSlots(array $slots, ThemeContract $theme): array
{
return $this->supportsBuilderTheme($theme)
? array_replace($slots, ['header' => ['bb-navbar'], 'footer' => ['bb-footer']])
: $slots;
}
public function headerFooterCanvasAssets(array $assets, ThemeContract $theme): array
{
if (!$this->supportsBuilderTheme($theme)) {
return $assets;
}
$assets['styles'] = array_merge($assets['styles'] ?? [], [
'https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css',
'css/style.css',
]);
$assets['scripts'] = array_merge($assets['scripts'] ?? [], [
'https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js',
]);
return $assets;
}
private function supportsBuilderTheme(ThemeContract $theme): bool
{
$folders = $theme instanceof BuilderTheme ? $theme->getThemeFolders() : [$theme->getFolder()];
return in_array(realpath(__DIR__), array_map('realpath', $folders), true);
}
/**
* @return void
* @throws ReflectionException
*/
private function registerAdminNotice(): void
{
Action::getInstance()->addAction('admin_notices', function () {
echo '<div class="alert dismissable alert-danger center sticky">' .
t__(
'You must upgrade your system to at least v2.3 in order to use the new Bootstrap Business theme.',
$this->id()
) .
'</div>';
});
}
}