-
Notifications
You must be signed in to change notification settings - Fork 14
/
extension.driver.php
75 lines (59 loc) · 2.13 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
class extension_publish_tabs extends Extension {
public function uninstall() {
Symphony::Database()->query("DROP TABLE `tbl_fields_publish_tabs`");
}
public function install() {
Symphony::Database()->query(
"CREATE TABLE IF NOT EXISTS `tbl_fields_publish_tabs` (
`id` int(11) NOT NULL auto_increment,
`field_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"
);
return true;
}
public function getSubscribedDelegates() {
return array(
array(
'page' => '/backend/',
'delegate' => 'InitaliseAdminPageHead',
'callback' => 'initializeAdmin'
),
);
}
public function initializeAdmin($context) {
$page = Administration::instance()->Page;
$context = $page->getContext();
$callback = Administration::instance()->getPageCallback();
// only proceed on New or Edit publish pages
if ($page instanceof contentPublish and in_array($context['page'], array('new', 'edit'))) {
$page->addStylesheetToHead(URL . '/extensions/publish_tabs/assets/publish_tabs.publish.css', 'screen', 9001);
$page->addScriptToHead(URL . '/extensions/publish_tabs/assets/publish_tabs.publish.js', 9002);
include_once(TOOLKIT . '/class.sectionmanager.php');
$section_id = SectionManager::fetchIDFromHandle($callback['context']['section_handle']);
$section = SectionManager::fetch($section_id);
if( !$section instanceof Section ) return;
$tabs = array();
$current_tab = '';
$index = -1;
foreach($section->fetchFieldsSchema() as $i => $field) {
if ($i == 0 && $field['type'] != 'publish_tabs'){
$current_tab = 'untitled-tab';
$tabs[++$index]['tab_id'] = $current_tab;
}
if ($field['type'] == 'publish_tabs') {
$current_tab = $field['id'];
$tabs[++$index]['tab_id'] = $current_tab;
} else {
$tabs[$index][$field['location']][] = 'field-' . $field['id'];
}
}
$page->addElementToHead(new XMLElement(
'script',
"Symphony.Context.add('publish-tabs', " . json_encode($tabs) . ")",
array('type' => 'text/javascript')
), 9003);
}
}
}