-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdrupalcrudadminmodule.install
108 lines (95 loc) · 3.38 KB
/
drupalcrudadminmodule.install
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
<?php
/**
* @file
* Defines the module management hooks required by Drupal.
*
* @author Bastian Feder <[email protected]>
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @copyright Copyright (c) 2013 Liip Inc.
*/
use Assert\Assertion;
use Liip\Drupal\Modules\DrupalConnector\Common;
use Liip\Drupal\Modules\DrupalConnector\ConnectorFactory;
use Liip\Drupal\Modules\EventManager\Registry\D7Config\EventSubjects;
use Liip\Drupal\Modules\EventManager\SubjectFactory;
use Liip\Drupal\Modules\Registry\RegistryException;
use Liip\Drupal\Modules\Registry\RegistryInterface;
/**
* Sets up the environment for the module to function properly
*
* @see hook_enable()
*/
function drupalcrudadminmodule_enable()
{
/** @var \Liip\Drupal\Modules\DrupalConnector\Common $dcc */
$dcc = ConnectorFactory::getCommonConnector();
$assertion = new Assertion();
$registry = new EventSubjects($assertion);
$factory = new SubjectFactory($registry, $assertion);
_drupalcrudadminmodule_initSubject('liip.crudadmin.actions.list', $factory, $dcc);
_drupalcrudadminmodule_initSubject('liip.crudadmin.actions.create', $factory, $dcc);
_drupalcrudadminmodule_initSubject('liip.crudadmin.actions.read', $factory, $dcc);
_drupalcrudadminmodule_initSubject('liip.crudadmin.actions.update', $factory, $dcc);
_drupalcrudadminmodule_initSubject('liip.crudadmin.actions.delete', $factory, $dcc);
}
/**
* Processes cleanup operations so the system stays clean after deactivation of the module.
*
* @see hook_disable()
*/
function drupalcrudadminmodule_disable()
{
/** @var \Liip\Drupal\Modules\DrupalConnector\Common $dcc */
$dcc = ConnectorFactory::getCommonConnector();
$assertion = new Assertion();
$registry = new EventSubjects($assertion);
_drupalcrudadminmodule_unregisterEvent('liip.crudadmin.actions.list', $registry, $dcc);
_drupalcrudadminmodule_unregisterEvent('liip.crudadmin.actions.create', $registry, $dcc);
_drupalcrudadminmodule_unregisterEvent('liip.crudadmin.actions.read', $registry, $dcc);
_drupalcrudadminmodule_unregisterEvent('liip.crudadmin.actions.update', $registry, $dcc);
_drupalcrudadminmodule_unregisterEvent('liip.crudadmin.actions.delete', $registry, $dcc);
}
/**
* Removes event from registry.
*
* @param string $eventName
* @param RegistryInterface $registry
* @param Common $dcc
*/
function _drupalcrudadminmodule_unregisterEvent($eventName, RegistryInterface $registry, Common $dcc)
{
try {
$registry->unregister($eventName);
} catch (RegistryException $e) {
$dcc->watchdog(
'Liip Drupal CRUD Admin Module',
$e->getMessage(),
array('event' => $eventName, 'registry' => $registry),
WATCHDOG_WARNING
);
return;
}
$dcc->watchdog(
'Liip Drupal CRUD Admin Module',
'Event successfully removed: ' . $eventName,
null,
WATCHDOG_NOTICE
);
}
/**
* Creates an event to be emitted somewhen.
*
* @param string $eventName
* @param SubjectFactory $factory
* @param Common $dcc
*/
function _drupalcrudadminmodule_initSubject($eventName, SubjectFactory $factory, Common $dcc)
{
$factory->initSubject($eventName);
$dcc->watchdog(
'Liip Drupal CRUD Admin Module',
'Event subject successfully registered: ' . $eventName,
null,
WATCHDOG_NOTICE
);
}