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

multi_select::build_multi_select()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 9
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 multi_select extends cfg_field_base
18
{
19
	/**
20
	 * @inheritdoc
21
	 */
22
	public function get_name()
23
	{
24
		return 'multi_select';
25
	}
26
27
	/**
28
	 * {@inheritdoc}
29
	 */
30
	public function prep_field(array &$vars, array &$type, $field, array $db_settings)
31
	{
32
		$vars['method'] ='build_multi_select';
33
		$vars['params'][] = $field;
34
		$type[0] = 'custom';
35
	}
36
37
	/**
38
	 * Used to add multi-select drop down in blocks config
39
	 *
40
	 * @param array $option_ary
41
	 * @param mixed $selected_items
42
	 * @param string $field
43
	 * @return string
44
	 */
45
	public function build_multi_select(array $option_ary, $selected_items, $field)
46
	{
47
		$this->ptemplate->assign_vars(array(
48
			'field'		=> $field,
49
			'options'	=> $option_ary,
50
			'selected'	=> cfg_utils::ensure_array($selected_items),
51
		));
52
53
		return $this->ptemplate->render_view('blitze/sitemaker', 'cfg_fields/multi_select.html', 'multi_select');
54
55
	}
56
}
57