/
MmenuModule.php
81 lines (67 loc) · 1.93 KB
/
MmenuModule.php
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
<?php
declare(strict_types=1);
/*
* This file is part of the ContaoMmenuBundle.
*
* (c) Dirk Klemmt
* (c) inspiredminds
*
* @license MIT
*/
namespace DirkKlemmt\ContaoMmenuBundle\FrontendModule;
use Contao\BackendTemplate;
use DirkKlemmt\ContaoMmenuBundle\Helper\MmenuHelper;
class MmenuModule extends \Contao\ModuleNavigation
{
/**
* Template.
*
* @var string
*/
protected $strTemplate = 'mod_mmenu';
/**
* Template.
*
* @var string
*/
protected $strTemplateJs = 'mmenu_default';
/**
* Display a wildcard in the back end.
*/
public function generate(): string
{
if (TL_MODE === 'BE') {
// --- create BE template for mmenu module
$template = new BackendTemplate('be_wildcard');
$template->wildcard = '### '.utf8_strtoupper($GLOBALS['TL_LANG']['FMD']['mmenu'][0]).' ###';
$template->title = $this->headline;
$template->id = $this->id;
$template->link = $this->name;
$template->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id='.$this->id;
return $template->parse();
}
// replace default (HTML) template with chosen one
if ($this->customTpl) {
$this->strTemplate = $this->customTpl;
}
// replace default (JS) template with chosen one
if ($this->dk_mmenuJsTpl) {
$this->strTemplateJs = $this->dk_mmenuJsTpl;
}
return parent::generate();
}
/**
* Generate the module.
*/
protected function compile(): void
{
// Navigation template fallback
if ('' === $this->navigationTpl) {
$this->navigationTpl = 'nav_mmenu';
}
// Build the navigation items
parent::compile();
// Add the JavaScript to TL_BODY
MmenuHelper::processModuleSettings($this, $this->strTemplateJs);
}
}