forked from 64j/multifields
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultifields.plugin.php
More file actions
64 lines (55 loc) · 2.03 KB
/
multifields.plugin.php
File metadata and controls
64 lines (55 loc) · 2.03 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
<?php
/**
* multifields
*
* Creating custom fields for documents
*
* @category plugin
* @version 2.0
* @package evo
* @internal @properties &multifields_storage=Data storage;list;default,files,database;default &multifields_debug=Plugin debug;list;no,yes;no
* @internal @events OnAfterLoadDocumentObject,OnWebPageInit,OnBeforeManagerPageInit,OnManagerMainFrameHeaderHTMLBlock,OnDocFormDelete,OnDocFormSave
* @internal @modx_category Manager and Admin
* @internal @installset base,sample
* @author 64j
*/
//@TODO в гетинстанс прокинуть параметры
if(!function_exists('mfc')){
function mfc($params = []) {
return \Multifields\Base\Core::getInstance($params);
}
}
Event::listen('evolution.OnManagerMainFrameHeaderHTMLBlock', function ($params) {
if (in_array(evo()->manager->action, [3, 4, 17, 27, 72, 112])) {
return mfc()->getStartScripts();
}
});
Event::listen('evolution.OnManagerMainFrameHeaderHTMLBlock', function ($params) {
if (isset($_REQUEST['mf-action']) && !empty($_REQUEST['action'])) {
$className = !empty($_REQUEST['class']) ? $_REQUEST['class'] : '';
if (class_exists($className)) {
$class = new $className();
$method = 'action' . ucfirst(strtolower($_REQUEST['action']));
if (is_callable([$className, $method])) {
try {
echo $class->$method($_REQUEST);
} catch (Error $exception) {
echo json_encode([
'error' => (string)$exception
], JSON_UNESCAPED_UNICODE);
}
} else {
echo 'Method ' . $method . ' not found in class ' . $className . '!';
}
} else {
echo 'Class ' . $className . ' not found!';
}
exit;
}
});
Event::listen('evolution.OnDocFormSave', function ($params) {
mfc()->saveData();
});
Event::listen('evolution.OnDocFormDelete', function ($params) {
mfc()->deleteData();
});