Settings.php
2.9 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
namespace ACP\Editing;
use AC;
use AC\View;
class Settings extends AC\Settings\Column
implements AC\Settings\Header
{
const NAME = 'edit';
private $edit;
/**
* @var AC\Settings\Column[]
*/
protected $sections = [];
/**
* @var boolean
*/
private $refresh_column;
public function __construct(AC\Column $column, $refresh_column = false)
{
parent::__construct($column);
$this->set_refresh($refresh_column);
}
/**
* @param boolean $enable
*/
public function set_refresh($enable)
{
$this->refresh_column = $enable;
}
/**
* @param AC\Settings\Column $setting
*
* @return $this
*/
public function add_section(AC\Settings\Column $setting)
{
$this->sections[$setting->get_name()] = $setting;
return $this;
}
/**
* @param string $name
*
* @return AC\Settings\Column|null
*/
public function get_section($name)
{
return $this->sections[$name] ?? null;
}
protected function define_options()
{
return [self::NAME => 'on'];
}
/**
* @return string
*/
private function get_instruction()
{
$view = new View([
'object_type' => $this->column->get_list_singular_label(),
]);
$view->set_template('tooltip/inline-editing');
return $view->render();
}
public function create_header_view()
{
$filter = $this->get_edit();
$view = new View([
'title' => __('Enable Editing', 'codepress-admin-columns'),
'dashicon' => 'dashicons-edit',
'state' => $filter,
]);
$view->set_template('settings/header-icon');
return $view;
}
protected function create_toggle_element()
{
$setting = new AC\Form\Element\Toggle(self::NAME, '', $this->get_value(self::NAME) === 'on', 'on', 'off');
$setting->add_class('ac-setting-input_' . self::NAME);
if ($this->refresh_column) {
$setting->set_attribute('data-refresh', 'column');
}
return $setting;
}
public function create_view()
{
$view = new View();
$view->set('label', __('Inline Editing', 'codepress-admin-columns'))
->set('instructions', $this->get_instruction())
->set('setting', $this->create_toggle_element());
foreach ($this->sections as $section) {
$view->set('sections', [$section->create_view()]);
}
return $view;
}
/**
* @return string
*/
public function get_edit()
{
return $this->edit;
}
/**
* @param string $edit
*
* @return $this
*/
public function set_edit($edit)
{
$this->edit = $edit;
return $this;
}
public function is_active()
{
return 'on' === $this->get_edit();
}
}