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 select extends cfg_field_base |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @inheritdoc |
22
|
|
|
*/ |
23
|
|
|
public function get_name() |
24
|
|
|
{ |
25
|
|
|
return 'select'; |
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, size, multi select, toggle key |
34
|
|
|
$type += array('', 1, 0, ''); |
35
|
|
|
|
36
|
|
|
$vars['method'] = 'build_select'; |
37
|
|
|
$vars['params'][] = $field; |
38
|
|
|
$vars['params'][] = (int) $type[1]; // size |
39
|
|
|
$vars['params'][] = (bool) $type[2]; // multi select |
40
|
|
|
$vars['params'][] = (string) $type[3]; // togggle key |
41
|
|
|
$type[0] = 'custom'; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Used to add a select drop down in blocks config |
46
|
|
|
* |
47
|
|
|
* @param array $options |
48
|
|
|
* @param string $selected |
49
|
|
|
* @param string $field |
50
|
|
|
* @param int $size |
51
|
|
|
* @param bool $multi_select |
52
|
|
|
* @param string $togglable_key |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
|
|
public function build_select(array $options, $selected, $field, $size = 1, $multi_select = false, $togglable_key = '') |
56
|
|
|
{ |
57
|
|
|
return array( |
58
|
|
|
'field' => $field, |
59
|
|
|
'selected' => cfg_utils::ensure_array($selected), |
60
|
|
|
'options' => $options, |
61
|
|
|
'size' => $size, |
62
|
|
|
'multi_select' => $multi_select, |
63
|
|
|
'togglable_key' => $togglable_key, |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
|
|
public function get_template() |
71
|
|
|
{ |
72
|
|
|
return '@blitze_sitemaker/cfg_fields/select.html'; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|