forked from DeuxHuitHuit/backend_add_script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.driver.php
54 lines (49 loc) · 1.87 KB
/
extension.driver.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
<?php
Class extension_backend_add_script extends Extension
{
/**
* Set the delegates
*/
public function getSubscribedDelegates()
{
return array(
array(
'page' => '/backend/',
'delegate' => 'InitaliseAdminPageHead',
'callback' => 'addScriptToHead'
)
);
}
/**
* Add script to the <head>-section of the admin area
*/
public function addScriptToHead($context)
{
// We have to put a lot of javascript here since there are missing some handles:
$javaScript = "\n";
$callback = Administration::instance()->getPageCallback();
// Current callback and action:
$driver = '"'.$callback['driver'].'"';
$action = isset($callback['context']['page']) ? '"'.$callback['context']['page'].'"' : 'false';
$section= isset($callback['context']['section_handle']) ? '"'.$callback['context']['section_handle'].'"' : 'false';
$idEntry= isset($callback['context']['entry_id']) ? '"'.$callback['context']['entry_id'].'"' : 'false';
// User information:
$author = null;
if (is_callable(array('Symphony', 'Author'))) {
$author = Symphony::Author();
} else {
$author = Administration::instance()->Author;
}
$javaScript.= "var user_id = ".$author->get('id').";\n";
$javaScript.= "var user_type = '".$author->get('user_type')."';\n";
$javaScript.= "var driver = ".$driver.";\n";
$javaScript.= "var action = ".$action.";\n";
$javaScript.= "var section = ".$section.";\n";
$javaScript.= "var id_entry = ".$idEntry.";\n";
$tag = new XMLElement('script', $javaScript, array('type'=>'text/javascript'));
Administration::instance()->Page->addElementToHead($tag);
Administration::instance()->Page->addScriptToHead(URL.'/extensions/backend_add_script/assets/custom.js');
Administration::instance()->Page->addStylesheetToHead(URL.'/extensions/backend_add_script/assets/custom.css');
}
}
?>