Passed
Push — develop ( b3eda6...9f2d35 )
by Daniel
03:59 queued 40s
created

multi_input::get_template()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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