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

radio::__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 radio extends cfg_field_base
18
{
19
	/**
20
	 * @inheritdoc
21
	 */
22
	public function get_name()
23
	{
24
		return 'radio';
25
	}
26
27
	/**
28
	 * {@inheritdoc}
29
	 */
30
	public function prep_field(array &$vars, array &$type, $field, array $db_settings)
31
	{
32
		if (!isset($type[1]))
33
		{
34
			$vars['method'] = 'build_radio';
35
			$vars['params'][] = $field;
36
			$type[0] = 'custom';
37
		}
38
	}
39
40
	/**
41
	 * Build radio buttons other than yes_no/enable_disable in blocks config
42
	 *
43
	 * @param array $option_ary
44
	 * @param mixed $selected_item
45
	 * @param string $field
46
	 * @return string
47
	 */
48
	public function build_radio(array $option_ary, $selected_item, $field)
49
	{
50
		$this->ptemplate->assign_vars(array(
51
			'field'		=> $field,
52
			'options'	=> $option_ary,
53
			'selected'	=> (is_array($selected_item)) ? array_pop($selected_item) : $selected_item,
54
		));
55
56
		return $this->ptemplate->render_view('blitze/sitemaker', 'cfg_fields/radio.html', 'radio');
57
	}
58
}
59