forked from symphonists/publishfiltering
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.driver.php
111 lines (94 loc) · 3.31 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
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
109
110
111
<?php
class Extension_PublishFiltering extends Extension {
private $_incompatible_publishpanel = array('mediathek', 'imagecropper', 'readonlyinput');
private $_fields = array();
private $_options = array();
public function getSubscribedDelegates() {
return array(
array(
'page' => '/backend/',
'delegate' => 'InitaliseAdminPageHead',
'callback' => 'createInterface'
)
);
}
/**
* Append publish filtering interface
*/
public function createInterface($context) {
$callback = Symphony::Engine()->getPageCallback();
if($callback['driver'] == 'publish' && $callback['context']['page'] == 'index') {
$this->getFields($callback['context']['section_handle']);
// Append assets
Administration::instance()->Page->addScriptToHead(URL . '/extensions/publishfiltering/assets/selectize.js', 1001);
Administration::instance()->Page->addStylesheetToHead(URL . '/extensions/publishfiltering/assets/publishfiltering.publish.css', 'screen', 1002);
Administration::instance()->Page->addScriptToHead(URL . '/extensions/publishfiltering/assets/publishfiltering.publish.js', 1003);
Administration::instance()->Page->addElementToHead(new XMLElement(
'script',
"Symphony.Context.add('publishfiltering', " . json_encode($this->_options) . ")",
array('type' => 'text/javascript')
), 1004);
// Append drawer
Administration::instance()->Page->insertDrawer(
Widget::Drawer('publishfiltering', __('Filter Entries'), $this->createDrawer())
);
}
}
/**
* Create drawer
*/
public function createDrawer() {
$form = Widget::Form(null, 'get', 'publishfiltering');
$div = new XMLElement('div', null, array('class' => 'publishfiltering-controls'));
$div->appendChild(
Widget::Select('fields', $this->_fields, array(
'class' => 'publishfiltering-fields'
))
);
$div->appendChild(
Widget::Select('comparison', array(
array('contains', false, __('contains')),
array('is', false, __('is'))
), array(
'class' => 'publishfiltering-comparison'
))
);
$form->appendChild($div);
$form->appendChild(
Widget::Input('value', null, 'text', array(
'class' => 'publishfiltering-search',
'placeholder' => __('Type to search') . ' …')
)
);
return $form;
}
/**
* Get field names
*/
public function getFields($section_handle) {
$sectionManager = new SectionManager(Symphony::Engine());
$section_id = $sectionManager->fetchIDFromHandle($section_handle);
if(!$section_id) return;
// Filterable sections
$section = $sectionManager->fetch($section_id);
foreach($section->fetchFilterableFields() as $field) {
if(in_array($field->get('type'), $this->_incompatible_publishpanel)) continue;
$this->_fields[] = array($field->get('element_name'), false, $field->get('label'));
$this->getFieldOptions($field);
}
}
/**
* Get default field options
*/
public function getFieldOptions($field) {
if(method_exists($field, 'getToggleStates')) {
$options = $field->getToggleStates();
if(!empty($options)) $this->_options[$field->get('element_name')] = $options;
}
if(method_exists($field, 'findAllTags')) {
$options = $field->findAllTags();
if(!empty($options)) $this->_options[$field->get('element_name')] = $options;
}
}
}
?>