radio::build_radio()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 3
dl 0
loc 8
rs 10
c 2
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
use blitze\sitemaker\services\blocks\config\cfg_utils;
14
15
/**
16
 * @package sitemaker
17
 */
18
class radio extends cfg_field_base
19
{
20
	/**
21
	 * @inheritdoc
22
	 */
23
	public function get_name()
24
	{
25
		return 'radio';
26
	}
27
28
	/**
29
	 * {@inheritdoc}
30
	 */
31
	public function prep_field(array &$vars, array &$type, $field, array $db_settings)
32
	{
33
		if (!isset($type[1]))
34
		{
35
			$vars['method'] = 'build_radio';
36
			$vars['params'][] = $field;
37
			$type[0] = 'custom';
38
		}
39
	}
40
41
	/**
42
	 * Build radio buttons other than yes_no/enable_disable in blocks config
43
	 *
44
	 * @param array $option_ary
45
	 * @param mixed $selected_item
46
	 * @param string $field
47
	 * @return array
48
	 */
49
	public function build_radio(array $option_ary, $selected_item, $field)
50
	{
51
		$selected_item = cfg_utils::ensure_array($selected_item);
52
53
		return array(
54
			'field'		=> $field,
55
			'options'	=> $option_ary,
56
			'selected'	=> array_pop($selected_item),
57
		);
58
	}
59
60
	/**
61
	 * {@inheritdoc}
62
	 */
63
	public function get_template()
64
	{
65
		return '@blitze_sitemaker/cfg_fields/radio.html';
66
	}
67
}
68