-
Notifications
You must be signed in to change notification settings - Fork 0
/
TexterModuleBundle.php
51 lines (41 loc) · 1.28 KB
/
TexterModuleBundle.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
<?php
namespace SmartCore\Module\Texter;
use SmartCore\Bundle\CMSBundle\Entity\Node;
use SmartCore\Bundle\CMSBundle\Module\ModuleBundle;
use SmartCore\Module\Texter\Entity\TextItem;
class TexterModuleBundle extends ModuleBundle
{
protected $adminMenuBeforeCode = '<i class="fa fa-text-height"></i>';
/**
* Действие при создании ноды.
*
* @param Node $node
*/
public function createNode(Node $node)
{
$em = $this->container->get('doctrine.orm.entity_manager');
$item = new TextItem();
$item->setUser($this->container->get('security.token_storage')->getToken()->getUser());
$em->persist($item);
$em->flush($item);
$node->setParams([
'text_item_id' => $item->getId(),
'editor' => true,
]);
}
/**
* Действие при обновлении ноды.
*
* @param Node $node
*/
public function updateNode(Node $node)
{
$em = $this->container->get('doctrine.orm.entity_manager');
$item = $em->find(TextItem::class, $node->getParam('text_item_id'));
if ($item) {
$item->setEditor((int) $node->getParam('editor'));
$em->persist($item);
$em->flush($item);
}
}
}