|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Zikula package. |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright Zikula Foundation - https://ziku.la/ |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Zikula\Bundle\CoreInstallerBundle\Helper; |
|
15
|
|
|
|
|
16
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
18
|
|
|
use Zikula\BlocksModule\BlocksModuleInstaller; |
|
19
|
|
|
use Zikula\BlocksModule\Entity\BlockEntity; |
|
20
|
|
|
use Zikula\BlocksModule\Entity\BlockPlacementEntity; |
|
21
|
|
|
use Zikula\BlocksModule\Entity\BlockPositionEntity; |
|
22
|
|
|
use Zikula\Common\Translator\TranslatorInterface; |
|
23
|
|
|
use Zikula\ExtensionsModule\Entity\ExtensionEntity; |
|
24
|
|
|
|
|
25
|
|
|
class BlockHelper |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @var EntityManagerInterface |
|
29
|
|
|
*/ |
|
30
|
|
|
private $entityManager; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var TranslatorInterface |
|
34
|
|
|
*/ |
|
35
|
|
|
private $translator; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var ContainerInterface |
|
39
|
|
|
*/ |
|
40
|
|
|
private $container; |
|
41
|
|
|
|
|
42
|
|
|
public function __construct( |
|
43
|
|
|
EntityManagerInterface $entityManager, |
|
44
|
|
|
TranslatorInterface $translator, |
|
45
|
|
|
ContainerInterface $container |
|
46
|
|
|
) { |
|
47
|
|
|
$this->entityManager = $entityManager; |
|
48
|
|
|
$this->translator = $translator; |
|
49
|
|
|
$this->container = $container; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function createBlocks(): bool |
|
53
|
|
|
{ |
|
54
|
|
|
$installer = new BlocksModuleInstaller(); |
|
55
|
|
|
$installer->setBundle($this->container->get('kernel')->getModule('ZikulaBlocksModule')); |
|
56
|
|
|
$installer->setContainer($this->container); |
|
57
|
|
|
$installer->createDefaultData(); |
|
58
|
|
|
$this->createMainMenuBlock(); |
|
59
|
|
|
|
|
60
|
|
|
return true; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Create the main menu block. |
|
65
|
|
|
*/ |
|
66
|
|
|
private function createMainMenuBlock(): void |
|
67
|
|
|
{ |
|
68
|
|
|
/** @var ExtensionEntity $menuModuleEntity */ |
|
69
|
|
|
$menuModuleEntity = $this->entityManager->getRepository('ZikulaExtensionsModule:ExtensionEntity') |
|
70
|
|
|
->findOneBy(['name' => 'ZikulaMenuModule']); |
|
71
|
|
|
$blockEntity = new BlockEntity(); |
|
72
|
|
|
$mainMenuString = $this->translator->__('Main menu'); |
|
73
|
|
|
$blockEntity->setTitle($mainMenuString); |
|
74
|
|
|
$blockEntity->setBkey('ZikulaMenuModule:\Zikula\MenuModule\Block\MenuBlock'); |
|
75
|
|
|
$blockEntity->setBlocktype('Menu'); |
|
76
|
|
|
$blockEntity->setDescription($mainMenuString); |
|
77
|
|
|
$blockEntity->setModule($menuModuleEntity); |
|
78
|
|
|
$blockEntity->setProperties([ |
|
79
|
|
|
'name' => 'mainMenu', |
|
80
|
|
|
'options' => '{"template": "@ZikulaMenuModule/Override/bootstrap_fontawesome.html.twig"}' |
|
81
|
|
|
]); |
|
82
|
|
|
$this->entityManager->persist($blockEntity); |
|
83
|
|
|
|
|
84
|
|
|
/** @var BlockPositionEntity $topNavPosition */ |
|
85
|
|
|
$topNavPosition = $this->entityManager->getRepository('ZikulaBlocksModule:BlockPositionEntity') |
|
86
|
|
|
->findOneBy(['name' => 'topnav']); |
|
87
|
|
|
$placement = new BlockPlacementEntity(); |
|
88
|
|
|
$placement->setBlock($blockEntity); |
|
89
|
|
|
$placement->setPosition($topNavPosition); |
|
90
|
|
|
$placement->setSortorder(0); |
|
91
|
|
|
$this->entityManager->persist($placement); |
|
92
|
|
|
|
|
93
|
|
|
$this->entityManager->flush(); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|