|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* |
|
5
|
|
|
* @package sitemaker |
|
6
|
|
|
* @copyright (c) 2019 Daniel A. (blitze) |
|
7
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
|
8
|
|
|
* |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace blitze\sitemaker\services\blocks\config\fields; |
|
12
|
|
|
|
|
13
|
|
|
use blitze\sitemaker\services\blocks\config\cfg_utils; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @package sitemaker |
|
17
|
|
|
*/ |
|
18
|
|
|
class checkbox extends cfg_field_base |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @inheritdoc |
|
22
|
|
|
*/ |
|
23
|
|
|
public function get_name() |
|
24
|
|
|
{ |
|
25
|
|
|
return 'checkbox'; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* {@inheritdoc} |
|
30
|
|
|
*/ |
|
31
|
|
|
public function prep_field(array &$vars, array &$type, $field, array $db_settings) |
|
32
|
|
|
{ |
|
33
|
|
|
// set defaults for types: field type, css class |
|
34
|
|
|
$type += array('', 0); |
|
35
|
|
|
|
|
36
|
|
|
$vars['method'] = 'build_checkbox'; |
|
37
|
|
|
$vars['params'][] = $field; |
|
38
|
|
|
$vars['params'][] = (string) $type[1]; // css class to be applied to list |
|
39
|
|
|
$type[0] = 'custom'; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Used to build multi-column checkboxes for blocks config |
|
44
|
|
|
* |
|
45
|
|
|
* if multi-dimensional array, we break the checkboxes into columns ex. |
|
46
|
|
|
* array( |
|
47
|
|
|
* 'news' => array( |
|
48
|
|
|
* 'field1' => 'Label 1', |
|
49
|
|
|
* 'field2' => 'Label 2', |
|
50
|
|
|
* ), |
|
51
|
|
|
* 'articles' => array( |
|
52
|
|
|
* 'field1' => 'Label 1', |
|
53
|
|
|
* 'field2' => 'Label 2', |
|
54
|
|
|
* ), |
|
55
|
|
|
* ) |
|
56
|
|
|
* @param array $option_ary |
|
57
|
|
|
* @param mixed $selected_items |
|
58
|
|
|
* @param string $field |
|
59
|
|
|
* @param bool $sortable |
|
60
|
|
|
* @return array |
|
61
|
|
|
*/ |
|
62
|
|
|
public function build_checkbox(array $option_ary, $selected_items, $field, $sortable = false) |
|
63
|
|
|
{ |
|
64
|
|
|
$column_class = 'col '; |
|
65
|
|
|
$selected_items = cfg_utils::ensure_array($selected_items); |
|
66
|
|
|
$option_ary = cfg_utils::ensure_multi_array($option_ary, $column_class); |
|
67
|
|
|
|
|
68
|
|
|
return array( |
|
69
|
|
|
'field' => $field, |
|
70
|
|
|
'selected' => $selected_items, |
|
71
|
|
|
'columns' => $option_ary, |
|
72
|
|
|
'class' => $column_class, |
|
73
|
|
|
'sortable' => $sortable, |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* {@inheritdoc} |
|
79
|
|
|
*/ |
|
80
|
|
|
public function get_template() |
|
81
|
|
|
{ |
|
82
|
|
|
return '@blitze_sitemaker/cfg_fields/checkbox.html'; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|