Completed
Push — release-3.2.0 ( 5118c1...fcf3db )
by Daniel
15:42
created

select::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2019 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\sitemaker\services\blocks\config\fields;
11
12
use blitze\sitemaker\services\blocks\config\cfg_utils;
13
14
/**
15
 * @package sitemaker
16
 */
17
class select extends cfg_field_base
18
{
19
	/**
20
	 * @inheritdoc
21
	 */
22
	public function get_name()
23
	{
24
		return 'select';
25
	}
26
27
	/**
28
	 * {@inheritdoc}
29
	 */
30
	public function prep_field(array &$vars, array &$type, $field, array $db_settings)
31
	{
32
		// set defaults for types: field type, size, multi select, toggle key
33
		$type += array('', 1, 0, '');
34
35
		$vars['method'] = 'build_select';
36
		$vars['params'][] = $field;
37
		$vars['params'][] = (int) $type[1];		// size
38
		$vars['params'][] = (bool) $type[2];	// multi select
39
		$vars['params'][] = (string) $type[3];	// togggle key
40
		$type[0] = 'custom';
41
	}
42
43
	/**
44
	 * Used to add a select drop down in blocks config
45
	 *
46
	 * @param array $options
47
	 * @param string $selected
48
	 * @param string $field
49
	 * @param int $size
50
	 * @param bool $multi_select
51
	 * @param string $togglable_key
52
	 * @return string
53
	 */
54
	public function build_select(array $options, $selected, $field, $size = 1, $multi_select = false, $togglable_key = '')
55
	{
56
		$this->ptemplate->assign_vars(array(
57
			'field'			=> $field,
58
			'selected'		=> cfg_utils::ensure_array($selected),
59
			'options'		=> $options,
60
			'size'			=> $size,
61
			'multi_select'	=> $multi_select,
62
			'togglable_key'	=> $togglable_key,
63
		));
64
65
		return $this->ptemplate->render_view('blitze/sitemaker', 'cfg_fields/select.html', 'select');
66
	}
67
}
68