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

multi_input::get_name()   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 0
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
/**
13
 * @package sitemaker
14
 */
15
class multi_input extends cfg_field_base
16
{
17
	/**
18
	 * @inheritdoc
19
	 */
20
	public function get_name()
21
	{
22
		return 'multi_input';
23
	}
24
25
	/**
26
	 * {@inheritdoc}
27
	 */
28
	public function prep_field(array &$vars, array &$type, $field, array $db_settings)
29
	{
30
		// set defaults for types: field type, sortable, full width
31
		$type += array('', 0, 1);
32
33
		if ($type[2])
34
		{
35
			$vars['params'][] = $vars['lang'];
36
			$vars['lang'] = '';
37
		}
38
39
		$vars['params'][] = array_filter((array) $db_settings[$field]);
40
		$vars['params'][] = $type[1];	// sortable
41
		$vars['params'][] = $field;
42
43
		$type[0] = 'custom';
44
		$vars['method'] = 'build_multi_input';
45
		$vars['params'] = array_reverse($vars['params']);
46
	}
47
48
	/**
49
	 * Used to add multi-select drop down in blocks config
50
	 *
51
	 * @param string $field
52
	 * @param bool $sortable
53
	 * @param array $values
54
	 * @param string $label
55
	 * @return string
56
	 */
57
	public function build_multi_input($field, $sortable, array $values, $label = '')
58
	{
59
		$this->ptemplate->assign_vars(array(
60
			'field'		=> $field,
61
			'values'	=> array_filter((array) $values),
62
			'sortable'	=> $sortable,
63
			'label'		=> $label,
64
		));
65
66
		return $this->ptemplate->render_view('blitze/sitemaker', 'cfg_fields/multi_input.html', 'multi_input_ui');
67
	}
68
}
69