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

code_editor::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 code_editor extends cfg_field_base
17
{
18
	/**
19
	 * @inheritdoc
20
	 */
21
	public function get_name()
22
	{
23
		return 'code_editor';
24
	}
25
26
	/**
27
	 * {@inheritdoc}
28
	 */
29
	public function prep_field(array &$vars, array &$type, $field, array $db_settings)
30
	{
31
		$vars['method'] = 'build_code_editor';
32
		$vars['params'] = array_reverse((array) $vars['params']);
33
		$vars['params'][] = $vars['lang_explain'];
34
		$vars['params'][] = $db_settings[$field];
35
		$vars['params'][] = $field;
36
		$vars['params'] = array_reverse($vars['params']);
37
38
		$type[0] = 'custom';
39
	}
40
41
	/**
42
	 * Used to add a code editor to blocks config
43
	 *
44
	 * @param string $key
45
	 * @param string $value
46
	 * @param string $explain
47
	 * @param array $data_props
48
	 * @param string $label
49
	 * @return array
50
	 */
51
	public function build_code_editor($key, $value, $explain, array $data_props = array(), $label = '')
52
	{
53
		return array(
54
			'key'			=> $key,
55
			'value'			=> $value,
56
			'label'			=> $label,
57
			'explain'		=> $explain,
58
			'attributes'	=> $this->get_code_editor_attributes($data_props),
59
			'fullscreen'	=> $this->fullscreen_allowed($data_props),
60
		);
61
	}
62
63
	/**
64
	 * @param array $data_props
65
	 * @return bool
66
	 */
67
	protected function fullscreen_allowed(array $data_props = array())
68
	{
69
		return (!isset($data_props['allow-full-screen']) || $data_props['allow-full-screen']);
70
	}
71
72
	/**
73
	 * @param array $data_props
74
	 * @return string
75
	 */
76
	protected function get_code_editor_attributes(array $data_props = array())
77
	{
78
		$attributes = '';
79
		foreach ($data_props as $prop => $value)
80
		{
81
			$value = (gettype($value) === 'boolean') ? (int) $value : $value;
82
			$attributes .= " data-{$prop}=\"{$value}\"";
83
		}
84
		return $attributes;
85
	}
86
87
	/**
88
	 * {@inheritdoc}
89
	 */
90
	public function get_template()
91
	{
92
		return '@blitze_sitemaker/cfg_fields/code_editor.html';
93
	}
94
}
95