-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMvbDesignSystem.php
More file actions
90 lines (75 loc) · 2.89 KB
/
MvbDesignSystem.php
File metadata and controls
90 lines (75 loc) · 2.89 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
<?php
namespace webhubworks\mvbdesignsystem;
use Craft;
use craft\base\Event;
use craft\events\RegisterTemplateRootsEvent;
use craft\events\RegisterUrlRulesEvent;
use craft\i18n\PhpMessageSource;
use craft\web\UrlManager;
use craft\web\View;
use Twig\Extra\Intl\IntlExtension;
use webhubworks\mvbdesignsystem\services\BrandColorsService;
use webhubworks\mvbdesignsystem\services\RenderComponentService;
use webhubworks\mvbdesignsystem\web\twig\BrandColorsExtension;
use webhubworks\mvbdesignsystem\web\twig\RenderComponentExtension;
use yii\base\Module as BaseModule;
/**
* MvbDesignSystem module
*
* @method static MvbDesignSystem getInstance()
* @property-read RenderComponentService $renderComponent
* @property-read BrandColorsService $brandColors
*/
class MvbDesignSystem extends BaseModule
{
/**
* Path to the components directory (supports only a single, one level directory)
*/
const COMPONENTS_PATH = 'components';
public function init(): void
{
Craft::setAlias('@webhubworks/mvbdesignsystem', __DIR__);
// Set the controllerNamespace based on whether this is a console or web request
if (Craft::$app->request->isConsoleRequest) {
$this->controllerNamespace = 'webhubworks\\mvbdesignsystem\\console\\controllers';
} else {
$this->controllerNamespace = 'webhubworks\\mvbdesignsystem\\controllers';
}
parent::init();
Craft::$app->i18n->translations['mvbdesignsystem'] = [
'class' => PhpMessageSource::class,
'sourceLanguage' => 'en',
'basePath' => __DIR__ . '/translations',
'allowOverrides' => true,
'forceTranslation' => true,
];
$this->setComponents([
'renderComponent' => RenderComponentService::class,
'brandColors' => BrandColorsService::class,
]);
$this->attachEventHandlers();
Craft::$app->view->registerTwigExtension(new IntlExtension());
Craft::$app->onInit(function () {
});
Craft::$app->view->registerTwigExtension(new RenderComponentExtension());
Craft::$app->view->registerTwigExtension(new BrandColorsExtension());
}
private function attachEventHandlers(): void
{
Event::on(
UrlManager::class,
UrlManager::EVENT_REGISTER_SITE_URL_RULES,
function (RegisterUrlRulesEvent $event) {
$event->rules['storybook-api/components/<componentId>'] = 'mvbdesignsystem/components/index';
}
);
Event::on(
View::class,
View::EVENT_REGISTER_SITE_TEMPLATE_ROOTS,
function (RegisterTemplateRootsEvent $event) {
// ToDo: Does this conflict with the default Craft template roots? templates/components?
$event->roots[self::COMPONENTS_PATH] = __DIR__ . '/' . self::COMPONENTS_PATH;
}
);
}
}